![](/img/trans.png)
[英]How to store aws athena output from python script in excel?
[英]Athena InvalidRequestException from Python
我正在嘗試從S3存儲桶讀取CSV文件並通過Python在Athena中創建表。 但是我正在執行它-
開始數據庫查詢
{'QueryExecutionId':'9cc82243-4220-47d0-8b63-0aa4f01fd590','ResponseMetadata':{'RequestId':'1c74bec6-663a-42ef-b9d1-73c7372eb4e1','HTTPStatusCode':200,'HTTPHeaders':{' content-type':'application / x-amz-json-1.1','date':'Thu,08 Nov 2018 15:37:11 GMT','x-amzn-requestid':'1c74bec6-663a-42ef- b9d1-73c7372eb4e1','content-length':'59','connection':'keep-alive'},'RetryAttempts':0}}
開始建立表格
追溯(最近一次通話):
QueryExecutionContext = {'Database':'athenadb'}中的文件“ C:/Users/Doc/PycharmProjects/aws-athena-repo/athena/app.py”,第61行
_api_call返回self中的文件“ C:\\ Program Files \\ Python37 \\ lib \\ site-packages \\ botocore \\ client.py”,第320行。_make_api_call(operation_name,kwargs)
_make_api_call中的文件“ C:\\ Program Files \\ Python37 \\ lib \\ site-packages \\ botocore \\ client.py”,行623引發error_class(parsed_response,operation_name)
botocore.errorfactory.InvalidRequestException:調用StartQueryExecution操作時發生錯誤(InvalidRequestException):第1:8行:輸入'CREATE EXTERNAL'處沒有可行的選擇
這是我的代碼示例-
print("Start of DB Query")
# Create a new database
db_query = 'CREATE DATABASE IF NOT EXISTS athenadb;'
response = client.start_query_execution(
QueryString=db_query,
ResultConfiguration={'OutputLocation': 's3://mybucket'})
print(response)
table_query = '''
CREATE EXTERNAL TABLE IF NOT EXISTS `athenadb.testtable`(
`id` int,
`ident` string,
`type` string,
`name` string,
`latitude_deg` double,
`longitude_deg` double,
`continent` string,
`iso_country` string,
`iso_region` string,
`municipality` string,
`scheduled_service` string,
`gps_code` string,
`iata_code` string,
`local_code` string,
`home_link` string,
`wikipedia_link` string,
`keywords` string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
WITH SERDEPROPERTIES (
'escape.delim'='\\')
STORED AS TEXTFILE
LOCATION 's3://mybucket/folder/' ;'''
print("Start of table creation")
response1 = client.start_query_execution(
QueryString=table_query,
ResultConfiguration={'OutputLocation': 's3://mybucket'},
QueryExecutionContext={'Database': 'athenadb'})
print(response1)
我不確定問題是否與ROW FORMAT DELIMITED有關。 我認為我的代碼很好。
詳細的步驟將不勝感激!
感謝adavace!
我將所有字段都用作String,將SERDEPROPERTIES用作OpenCSVSerde
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.