简体   繁体   中英

Running multiple MSCK REPAIR TABLE statements in AWS Athena

So I'm trying to execute the following in AWS Athena which allows to run only one statement at a time:

MSCK REPAIR TABLE some_database.some_table_001;
MSCK REPAIR TABLE some_database.some_table_002;
MSCK REPAIR TABLE some_database.some_table_003;

Problem is, I just don't have three statements, I have 700+ similar statements and would like to run those all 700+ in one go as batch.

So using AWS CloudShell CLI and tried running the following:

aws athena start-query-execution --query-string "MSCK REPAIR TABLE `some_table_001`;"  --work-group "primary" \
--query-execution-context Database=some_database \
--result-configuration "OutputLocation=s3://some_bucket/some_folder" 

..hoping I could use Excel to generate 700+ statements like this and run as batch

..but keep getting this error:

An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: line 1:1: mismatched input 'MSCK'. Expecting: 'ALTER', 'ANALYZE', 'CALL', 'COMMIT', 'CREATE', 'DEALLOCATE', 'DELETE', 'DESC', 'DESCRIBE', 'DROP', 'EXECUTE', 'EXPLAIN', 'GRANT', 'INSERT', 'PREPARE', 'RESET', 'REVOKE', 'ROLLBACK', 'SET', 'SHOW', 'START', 'UNLOAD', 'UPDATE', 'USE', <query>

Not sure what I'm doing wrong as the same MSCK command seems to run fine in Athena console. I know Athena is finicky when it comes to

`some_table_001` 

versus

'some_table_001' 

(different types of single quotes), I tried both but didn't get it work.

Any thoughts on possible solution?

For Amazon Athena, special characters other than underscore (_) are not supported in the table names and table column names.

Since your table name doesn't contain special characters, you don't need to wrap it in quotes or backticks. However, had your table name contained special characters then you would have had to use backticks. Refer below Amazon Athena Documentation for more details here .

Regarding running multiple MSCK REPAIR TABLE statements in Amazon Athena, you may also use any SDK like boto3 (Python).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM