简体   繁体   中英

AWS Athena not recognizing date?

I have two environments - prod and test. I am trying to figure out a query for Athena to show me access logs only for a specific month.

I am doing that based on a column 'date' with YYYY-MM-DD format, the underlying data are gzipped.txt files in s3.

My logs are limited to past 2 months. Because i want to automate the query, i rather use the interval month subtraction.

So - when running on test environment the clause below returns correct responses, showing me lines that have month of august WHERE month(date) = MONTH(current_date - interval '1' month)

unfortunately when running on prod, i get july and august.

It feels like i tried everything and still cant figure out what's wrong. I tried subselects, casting both sides of WHERE statement to VARCHAR, literally nothing seems to make an impact.

Does anyone have an idea?

for anyone who stumbles upon my issue again:) i found an answer - a dirty one, but working nonetheless.

My original query that Athena didn't care about month i wanted

SELECT date,
    time,
    bytes,
    request_ip,
    method,
    uri,
    status,
    user_agent
FROM "default"."logs"
WHERE month(date) = MONTH(current_date - interval '1' month)
AND user_agent LIKE '%gecko%';

a working query showing the month i wanted:

SELECT * 
FROM
(SELECT date,
    MONTH(date) as mn,
    time,
    bytes,
    request_ip,
    method,
    uri,
    status,
    user_agent
FROM "default"."logs"
WHERE user_agent LIKE '%gecko%') as in_table
WHERE mn = MONTH(current_date - interval '1' month);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM