How can I see the Amazon S3 source file for a row in an Athena table?

Last updated: 2019-10-10

I'm querying a table in Amazon Athena. I want to know which Amazon Simple Storage Service (Amazon S3) file is the source for each row in the output. 

Short Description

Use a SELECT $path query to find out which Amazon S3 file contains data that is returned by a specific row in an Athena table. This is useful for investigating unexpected data and for building queries that require information about the source data.

Resolution

Before you run the following queries, be sure that you have:

  • An Athena table. If you don't have a table, run a CREATE TABLE statement.
  • An AWS Identity and Access Management (IAM) user or role that has permissions to run Athena queries

To find the S3 file that is associated with a row of an Athena table:

1.    Run a SELECT query against your table to return the data that you want. In the following example, the table is flight_delays_pq.

SELECT * FROM "myDB"."flight_delays_pq" WHERE year=2019;

2.    To find the Amazon S3 source file for the data, run a query similar to the following:

SELECT "$path" FROM "myDB"."flight_delays_pq" WHERE year=2019;

The query returns the Amazon S3 path for the data:

s3://my-bucket/datasets_mytable/year=1989/data_file1.json

Did this article help you?

Anything we could improve?


Need more help?