amazon-web-services - Amazon Athena 中的 HIVE_INVALID_METADATA
问题描述
如何解决 Amazon Athena 中的以下错误?
HIVE_INVALID_METADATA: com.facebook.presto.hive.DataCatalogException: 错误: : 预期在 'struct<x-amz-request-id:string,action:string,label:string,category:string,when:string> 的位置 8 ' 但找到了 '-'。(服务:空;状态代码:0;错误代码:空;请求 ID:空)
在查看 AWS Glue 生成的连接到 Athena 的数据库表中的位置 8 时,我可以看到它有一个以attributes
相应结构数据类型命名的列:
struct <
x-amz-request-id:string,
action:string,
label:string,
category:string,
when:string
>
我的猜测是错误的发生是因为该attributes
字段并不总是被填充(参见_session.start
下面的事件)并且并不总是包含所有字段(例如DocumentHandling
下面的事件不包含该attributes.x-amz-request-id
字段)。解决此问题的适当方法是什么?我可以在 Glue 中设置一个可选列吗?可以(应该?)胶水用空字符串填充结构吗?其他选择?
背景:我有以下后端结构:
- Amazon PinPoint Analytics 从我的应用程序收集指标。
- PinPoint 事件流已配置为将事件转发到 Amazon Kinesis Firehose 传输流。
- Kinesis Firehose 将数据写入 S3
- 使用 AWS Glue 抓取 S3
- 使用 Athena 编写基于 AWS Glue 生成的数据库和表的查询
我可以看到 PinPoint 事件已成功添加到 S3 中的 json 文件中,例如
文件中的第一个事件:
{
"event_type": "_session.start",
"event_timestamp": 1524835188519,
"arrival_timestamp": 1524835192884,
"event_version": "3.1",
"application": {
"app_id": "[an app id]",
"cognito_identity_pool_id": "[a pool id]",
"sdk": {
"name": "Mozilla",
"version": "5.0"
}
},
"client": {
"client_id": "[a client id]",
"cognito_id": "[a cognito id]"
},
"device": {
"locale": {
"code": "en_GB",
"country": "GB",
"language": "en"
},
"make": "generic web browser",
"model": "Unknown",
"platform": {
"name": "macos",
"version": "10.12.6"
}
},
"session": {
"session_id": "[a session id]",
"start_timestamp": 1524835188519
},
"attributes": {},
"client_context": {
"custom": {
"legacy_identifier": "50ebf77917c74f9590c0c0abbe5522d2"
}
},
"awsAccountId": "672057540201"
}
同一文件中的第二个事件:
{
"event_type": "DocumentHandling",
"event_timestamp": 1524835194932,
"arrival_timestamp": 1524835200692,
"event_version": "3.1",
"application": {
"app_id": "[an app id]",
"cognito_identity_pool_id": "[a pool id]",
"sdk": {
"name": "Mozilla",
"version": "5.0"
}
},
"client": {
"client_id": "[a client id]",
"cognito_id": "[a cognito id]"
},
"device": {
"locale": {
"code": "en_GB",
"country": "GB",
"language": "en"
},
"make": "generic web browser",
"model": "Unknown",
"platform": {
"name": "macos",
"version": "10.12.6"
}
},
"session": {},
"attributes": {
"action": "Button-click",
"label": "FavoriteStar",
"category": "Navigation"
},
"metrics": {
"details": 40.0
},
"client_context": {
"custom": {
"legacy_identifier": "50ebf77917c74f9590c0c0abbe5522d2"
}
},
"awsAccountId": "[aws account id]"
}
接下来,AWS Glue 生成了一个数据库和一个表。具体来说,我看到有一个名为的列attributes
,其值为
struct <
x-amz-request-id:string,
action:string,
label:string,
category:string,
when:string
>
但是,当我尝试Preview table
从雅典娜,即执行查询
SELECT * FROM "pinpoint-test"."pinpoint_testfirehose" limit 10;
我收到前面描述的错误消息。
旁注,我试图删除该attributes
字段(通过从 Glue 编辑数据库表),但这会导致Internal error
从 Athena 执行 SQL 查询。
解决方案
这是一个已知的限制。Athena 表和数据库名称只允许下划线特殊字符#
Athena 表和数据库名称不能包含除下划线 (_) 以外的特殊字符。资料来源:http ://docs.aws.amazon.com/athena/latest/ug/known-limitations.html
推荐阅读
- python - 与 1 的补码二进制表示混淆
- ruby - Ruby Action Mailer 在开发中不会发送到 smtp
- php - php - 使用 odbc_fetch_array 的索引数组错误
- kotlin - Kotlin:预期 ')' 错误,代码未运行
- javascript - 将对象数据映射到 React 组件
- c++ - 如何在 OMNet++/Eclipse CDT (Linux) 中添加 gRPC 作为依赖项?
- python - 如何按每天的升序和降序对日期和时间进行排序,并为排序后的日期创建指定列?
- ruby-on-rails - 无法访问 datagrid rails 上的 current_user
- nim-lang - 如何忽略 nim 中的“断管”异常
- android - 谷歌日历事件链接未打开谷歌日历应用事件创建详细信息