在 ATHENA 中创建带分区的外部 table 会导致空 table

creating external table with partition in ATHENA results in empty table

我有一个 s3 位置,其中镶木地板 table 按日期列分区。

parquet_data ---
               --  dt=2021-07-27
                   files
               --  dt=2021-07-26
                   files

现在我想创建一个外部 table (CETAS)

table 由 dt 列分区。

CREATE EXTERNAL TABLE IF NOT EXISTS database.tbl_name (
  ACCOUNT_NUM                             bigint
, ID                                      bigint
, NAME                                    string
)

PARTITIONED BY (
  dt date)
ROW FORMAT SERDE
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
  's3://location/of/data/'
TBLPROPERTIES (
  'classification'='parquet',
  'typeOfData'='file'
);

当我从这个新 table 中 select 时,里面根本没有数据,只有 headers。

有什么我错过的东西吗?

我尝试过的东西。

使用现有分区数据创建新的 table 时,运行 此命令:

MSCK REPAIR TABLE database.tbl_name

来自MSCK REPAIR TABLE - Amazon Athena

The MSCK REPAIR TABLE command scans a file system such as Amazon S3 for Hive compatible partitions that were added to the file system after the table was created. MSCK REPAIR TABLE compares the partitions in the table metadata and the partitions in S3. If new partitions are present in the S3 location that you specified when you created the table, it adds those partitions to the metadata and to the Athena table.

这是必需的,因为分区不是由 Amazon Athena 或 AWS Glue 创建的,所以它不知道它们是否存在。