在Athena中,可以使用以下语法来按多个列对同一路径进行分区:
CREATE EXTERNAL TABLE table_name( column1 data_type, column2 data_type, .... ) PARTITIONED BY (partition_column1 data_type, partition_column2 data_type, ...) LOCATION 's3://bucket-name/path-to-table-data/'
可以基于这种表结构使用MSCK REPAIR TABLE语句自动添加分区或使用ALTER TABLE语句手动添加分区。
代码示例:
CREATE EXTERNAL TABLE mytable ( year int, month int, day int, data string ) PARTITIONED BY (country string, region string) LOCATION 's3://mybucket/data/table_name/';
MSCK REPAIR TABLE mytable;
ALTER TABLE mytable ADD PARTITION (country='China', region='Beijing') LOCATION 's3://mybucket/data/table_name/country=China/region=Beijing/';