PyAthenaJDBC中的蜂巢参数(AWS athena)

2024-05-13 03:24:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python模块PyAthenaJDBC,以便使用提供的JDBC驱动程序查询Athena。 以下是链接:https://pypi.python.org/pypi/PyAthenaJDBC/

连接已成功建立,查询也正在运行(显示数据库、显示表、选择…) 但是,每当我试图使用配置单元参数(如“ROW FORMAT SERDE…”)定义自定义表时,它就不起作用了, 这是我的代码:

class PyAthenaLoader():
    def connecti(self):
        self.conn = pyathenajdbc.connect(
                                         access_key=access_key_id,
                                         secret_key=secret_key_id,
                                         region_name = "us-west-2",
                                         s3_staging_dir="s3://aws-athena-query-results-332333536009-us-west-2")
    def create(self):
        try:
            with self.conn.cursor() as cursor:
                cursor.execute(
                              """CREATE EXTERNAL TABLE IF NOT EXISTS sales4 (
                              Day_ID int, 
                              Product_Id string,
                              Store_Id string, 
                              Sales_Units int,
                              Sales_Cost float, 
                              Currency string
                              ) 
                              ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
                              WITH SERDEPROPERTIES (
                              'serialization.format' = '|',
                              'field.delim' = '|',
                              'collection.delimm = 'undefined',
                              'mapkey.delim' = 'undefined'
                              ) LOCATION 's3://athena/';
                              """)

Error : line 1:8: no viable alternative at input 'CREATE EXTERNAL' (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: 0cca6f3e-fe9e-11e6-be4f-a3b28f284a77)

PS:同样的查询在控制台管理中工作得很好! 有什么帮助吗?在


Tags: keyorgselfpypiidformatstrings3