【问题标题】:AWS Athena table creation fails with “no viable alternative at input 'create external'”AWS Athena 表创建失败,“在输入‘创建外部’时没有可行的替代方案”
【发布时间】:2019-04-09 12:01:44
【问题描述】:

这是我第一次尝试雅典娜,请温柔:)

此查询没有因错误而失败 -> 没有可行的替代方案

    CREATE EXTERNAL TABLE IF NOT EXISTS dev.mytokendata (
             'dateandtime' timestamp, 'requestid' string, 
 'ip' string, 'caller' string, 'token' string, 'requesttime' int, 
 'httpmethod' string, 'resourcepath' string, 'status' smallint, 
 'protocol' string, 'responselength' int ) 
    ROW FORMAT SERDE 'com.amazonaws.glue.serde.GrokSerDe'
    WITH SERDEPROPERTIES ( 
    'input.format'='%{TIMESTAMP_ISO8601:dateandtime}
      \s+\{\"requestId\":\s+\"%{USERNAME:requestid}\",
      \s+\"ip\":\s+\"%{IP:ip}\",
      \s+\"caller\":\s+\"%{USERNAME:caller}\",
      \s+\"token\":\s+\"%{USERNAME:token}\",
      \s+\"requestTime\":\s+\"%{INT:requesttime}\",
      \s+\"httpMethod\":\s+\"%{WORD:httpmethod}\",
      \s+\"resourcePath\":\s+\"%{UNIXPATH:resourcepath}\",
      \s+\"status\":\s+\"%{INT:status}\",
      \s+\"protocol\":\s+\"%{UNIXPATH:protocol}\",
      \s+\"responseLength:\"\s+\"%{INT:responselength}\"\s+\}' ) 
STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
LOCATION 's3://athena-abc/1234/' 
TBLPROPERTIES ('has_encrypted_data'='false', 'compressionType'='gzip');

这是我尝试解析的日志文件中的一行(.gz 文件)

2018-07-30T02:23:34.134Z { "requestId":
"810000-9100-1100-a100-f100000", "ip": "01.01.01.001", "caller": "-", 
"token": "1234-5678-78910-abcd", "requestTime": 
 "1002917414000", "httpMethod": "POST", "resourcePath": 
 "/MyApp/v1.0/MyService.wsdl", 
 "status": "200", "protocol": "HTTP/1.1", "responseLength": "1000" }

谁能指出可能出了什么问题?会有很大帮助的

【问题讨论】:

    标签: amazon-web-services amazon-s3 logstash-grok amazon-athena


    【解决方案1】:

    您在列名中不必要地使用了撇号,并且转义字符也存在问题。

    正确的版本:

     CREATE EXTERNAL TABLE mytokendata (
     `dateandtime` timestamp,
    `requestid` string, 
    `ip` string,
    `caller` string, 
    `token` string,
    `requesttime` int,  
    `httpmethod` string,
    `resourcepath` string,
    `status` smallint,  
    `protocol` string,
    `responselength` int ) 
    ROW FORMAT SERDE 'com.amazonaws.glue.serde.GrokSerDe'
    WITH SERDEPROPERTIES ( 
    'input.format'='%{TIMESTAMP_ISO8601:dateandtime}
      \\s+\\{\"requestId\":\\s+\"%{USERNAME:requestid}\",
      \\s+\"ip\":\\s+\"%{IP:ip}\",
      \\s+\"caller\":\\s+\"%{USERNAME:caller}\",
      \\s+\"token\":\\s+\"%{USERNAME:token}\",
      \\s+\"requestTime\":\\s+\"%{INT:requesttime}\",
      \\s+\"httpMethod\":\\s+\"%{WORD:httpmethod}\",
      \\s+\"resourcePath\":\\s+\"%{UNIXPATH:resourcepath}\",
      \\s+\"status\":\\s+\"%{INT:status}\",
      \\s+\"protocol\":\\s+\"%{UNIXPATH:protocol}\",
      \\s+\"responseLength:\"\\s+\"%{INT:responselength}\"\\s+\\}' ) 
    STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
    LOCATION 's3://athena-abc/1234/'  
    TBLPROPERTIES ('has_encrypted_data'='false', 'compressionType'='gzip');
    

    【讨论】:

    • 谢谢!如果可能的话,你能帮忙解决一下 grok 模式吗?
    • 我可以试试。可以发一份样本数据吗?
    • 抱歉无法在此处更新我的查询,我在问题中有一个示例数据行。会有很大帮助的!!
    • 我用 DDL 语句解决了问题,但 Grok 模式仍然存在问题。
    • 非常感谢!是的,Grok 模式部分是最成问题的..
    猜你喜欢
    • 2017-04-16
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    相关资源
    最近更新 更多