为雅典娜选择特定文件

Selecting specific files for athena

在 Athena 中创建 table 时,我无法使用特定文件创建 table。有没有办法从给定的存储桶中 select 所有以 "year_2019" 开头的文件?例如 s3://bucketname/prefix/year_2019*.csv


文档说的很清楚,不允许。

来自: https://docs.aws.amazon.com/athena/latest/ug/tables-location-format.html

Athena reads all files in an Amazon S3 location you specify in the CREATE TABLE statement, and cannot ignore any files included in the prefix. When you create tables, include in the Amazon S3 path only the files you want Athena to read. Use AWS Lambda functions to scan files in the source location, remove any empty files, and move unneeded files to another location.

我想知道社区是否找到了一些解决方法:)

遗憾的是,Athena 用于 S3 的文件系统抽象不支持此功能。它需要 table 个位置看起来像目录,Athena 会在列出文件时在位置末尾添加一个斜杠。

有一种方法可以创建仅包含选定文件的 tables,但据我所知它不支持通配符,仅支持明确的文件列表。

你所做的是用

创建一个table
STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat'

然后不是将 table 的 LOCATION 指向实际文件,而是将其指向带有单个 symlink.txt 文件的前缀(或将每个分区指向一个前缀为单个 symlink.txt)。在 symlink.txt 文件中,添加要包含在 table 中的文件的 S3 URI,每行一个。

据我所知,关于此功能的唯一文档是 S3 Inventory documentation for integrating with Athena

您还可以在此 Whosebug 回复中找到完整示例: