简体   繁体   English

在 AWS Athena 中创建外部表时出错

[英]Error when creating external table in AWS Athena

I get the following error when trying to create an external table in AWS Athena:尝试在 AWS Athena 中创建外部表时出现以下错误:

line 1:8: no viable alternative at input 'create external' (service: amazonathena; status code: 400; error code: invalidrequestexception

The code I'm using to create the table is the following.我用来创建表的代码如下。 It is based on an existing Athena table.它基于现有的 Athena 表。 I used SHOW CREATE to get the DDL code.我使用SHOW CREATE来获取 DDL 代码。

CREATE EXTERNAL TABLE h_test(
  test string
)
ROW FORMAT DELIMITED 
  FIELDS TERMINATED BY '#' 
  MAP KEYS TERMINATED BY 'undefined' 
WITH SERDEPROPERTIES ( 
  'collection.delim'='undefined') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://cleverea-staging/test/'
TBLPROPERTIES (
  'has_encrypted_data'='false')

I am not sure if it is a good idea to get the HiveQL DDL statement from one table in AWS Athena and reusing it to create another one.我不确定从 AWS Athena 中的一个表中获取 HiveQL DDL 语句并重新使用它来创建另一个表是否是个好主意。 There are multiple parameters that are not needed or specifically applied to that table.有多个参数不需要或专门应用于该表。

Most of the time the parameters OUTPUTFORMAT or TBLPROPERTIES is not needed.大多数时候不需要参数OUTPUTFORMATTBLPROPERTIES For instance, if your S3 bucket is encrypted by default mode or with KMS you don't need to mention it, AWS is smart enough to know how to decrypt the data if needed.例如,如果您的 S3 存储桶在默认模式下加密或使用 KMS 加密,则无需提及,AWS 足够聪明,知道如何在需要时解密数据。

It is a good practice to wrap database, table, and column names using backtick (`).使用反引号 (`) 包装数据库、表和列名称是一种很好的做法。

Good example:好的例子:

CREATE EXTERNAL TABLE IF NOT EXISTS `mydb`.`mytable` (
    `test` STRING,
    `test2` STRING
)
ROW FORMAT SERDE 
     'org.openx.data.jsonserde.JsonSerDe'
LOCATION
     's3://awsexamplebucket1-logs/AWSLogs/'

There is also a great generator online where you can easily convert any JSON (even complex Nested ones), CSV, TSV, or Log sample file to an Apache HiveQL DDL create table statement.还有一个很棒的在线生成器,您可以轻松地将任何 JSON(甚至是复杂的嵌套的)、CSV、TSV 或日志示例文件转换为 Apache Hive 创建语句。

Link: https://www.hivetablegenerator.com/链接: https://www.hivetablegenerator.com/

Official reference from AWS: https://docs.aws.amazon.com/athena/latest/ug/create-table.html AWS官方参考: https://docs.aws.amazon.com/athena/latest/ug/create-table.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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