在AWS Athena中创建存储桶表

问题描述

我在下面的查询中尝试创建存储桶表,但失败了。但是,如果我删除 子句CLUSTERED BY查询可能会成功。有什么建议吗?谢谢。

错误消息:no viable alternative at input create external

CREATE EXTERNAL TABLE nation5(
  n_nationkey bigint,n_name string,n_rgionkey int,n_comment string)
CLUSTERED BY 
  n_regionkey INTO 256 BUCKETS
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
WITH SERDEPROPERTIES ( 
  'path'='s3://test/testbucket/nation5/') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetoutputFormat'
LOCATION
  's3://test/testbucket/nation5/'

解决方法

CLUSTERED BY列需要放在方括号中,可完成以下工作:

CREATE EXTERNAL TABLE test.nation5(
  n_nationkey bigint,n_name string,n_regionkey int,n_comment string)
CLUSTERED BY 
  (n_regionkey) INTO 256 BUCKETS
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
WITH SERDEPROPERTIES ( 
  'path'='s3://test/testbucket/nation5/') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
  's3://test/testbucket/nation5/'

(您在列定义的n_rgionkey中也存在拼写错误。