使用AWS Athena创建外部表时遇InvalidRequestException错误求助
问题解决:AWS Athena 创建外部表报错 InvalidRequestException
核心错误原因
Athena基于Trino/Presto引擎,不支持Hive风格的CREATE EXTERNAL TABLE语法,引擎只认标准CREATE TABLE语法,外部表需通过WITH子句指定S3存储位置。另外你的SQL里还存在字段类型重复定义的错误。
修正后的SQL语句
CREATE TABLE IF NOT EXISTS dsoaws.gun_violence_csv2( incident_id varchar(10), incident_date date, state varchar(25), city_or_county varchar(25), address string, n_killed int, n_injured int, incident_url string, source_url string, incident_url_fields_missing int, -- 修正重复类型定义的错误 congressional_district int, gun_stolen string, gun_type string, incident_characteristics string, latitude float, location_description string, longitude float, n_guns_involved int, notes string, participant_age string, participant_age_group string, participant_gender string, participant_name string, participant_relationship string, participant_status string, participant_type string, sources string, state_house_district int, state_senate_district int ) WITH ( external_location = 's3://sagemaker-studio-898900188658-v9o4cft4fj/gun-violence/', format = 'csv', skip_header_line_count = 1 )
关键修正点
- 删掉
EXTERNAL关键字,改用WITH子句配置外部表属性,这是Athena兼容的标准写法 - 修复
incident_url_fields_missing int string的错误,移除重复的类型标识,保留int(若实际数据是字符串则改为string) - 把原
ROW FORMAT DELIMITED和TBLPROPERTIES里的配置迁移到WITH子句,使用Athena支持的参数名:format='csv'、skip_header_line_count=1
补充说明
Athena的SQL语法和Hive存在差异,创建外部表必须用CREATE TABLE + WITH(external_location=...)的形式,EXTERNAL关键字在当前引擎版本中不被识别,这就是报错提示"mismatched input 'EXTERNAL'"的根本原因。
内容的提问来源于stack exchange,提问作者chongochoo
相关产品推荐
相关产品推荐

