I have some data rows in AWS Athena table and I am trying to get the data from the last 1 hour. I am using awswrangler, I will post my snippet below. Basically, instead of querying all data and then filtering out only the last 1 hour with Python, I would like to do that in the Athena SQL query so that I get a faster response (and thus execution time of the program). My code is:
import awswrangler as wr
import boto3
session=boto3.Session()
df = wr.athena.read_sql_query(f"""SELECT *
FROM data_table""",
database="database",
keep_files = False,
boto3_session = session).sort_values('timestamp')
My progress:
I can get the current timestamp with "SELECT CURRENT_TIMESTAMP" , but this will return the timestamp in a date format. In order to get the last 1 hour, my idea is to convert 1 hour to milliseconds as well, and subtract it from the milliseconds of current timestamp and apply it as a filter.
NOTE! timestamp in the table is in milliseconds.