Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在AWS Athena中通过脚本加载所有分区?_Sql_Amazon Web Services_Amazon S3_Amazon Athena - Fatal编程技术网

Sql 如何在AWS Athena中通过脚本加载所有分区?

Sql 如何在AWS Athena中通过脚本加载所有分区?,sql,amazon-web-services,amazon-s3,amazon-athena,Sql,Amazon Web Services,Amazon S3,Amazon Athena,我有一个S3bucket:S3://bucket name/year=2018/month=xx/day=xx/hour=xx/minute=xx。 相应地,我在AWS Athena表上有5个分区列(年、月、日、小时、分钟) 我想在10月份加载所有数据。我试图 ALTER TABLE table_name add partition (all 5 partitions) location "s3://data/year=xx/month=xx/......."; 但是,我必须为所有分钟级分区编

我有一个S3
bucket:S3://bucket name/year=2018/month=xx/day=xx/hour=xx/minute=xx。

相应地,我在AWS Athena表上有5个分区列(年、月、日、小时、分钟)

我想在10月份加载所有数据。我试图

ALTER TABLE table_name add partition (all 5 partitions)
location "s3://data/year=xx/month=xx/.......";
但是,我必须为所有分钟级分区编写这个“altertable”命令,这是不可能的


可以在AWS Athena中编写脚本来加载所有分区吗

可以使用MSCK REPAIR TABLE命令

首先,您需要创建一个类似于下面的表

CREATE EXTERNAL TABLE `example`(
col1 string,
col2 string)
PARTITIONED BY ( 
`year` int, `year` `month`,`day`,`hour`,`minute`)
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://data'
之后,您应该能够运行“MSCK REPAIR TABLE”命令

如果要继续使用“ALTERTABLEADDPARITION”命令,则需要创建自定义脚本。在这种情况下,通常是boto3或jdbc athena驱动程序: