首页 > 解决方案 > 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 中设置一个可选列吗?可以(应该?)胶水用空字符串填充结构吗?其他选择?


背景:我有以下后端结构:

我可以看到 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 查询。

标签: amazon-web-servicesamazon-athenaaws-glueaws-pinpoint

解决方案


这是一个已知的限制。Athena 表和数据库名称只允许下划线特殊字符#

Athena 表和数据库名称不能包含除下划线 (_) 以外的特殊字符。资料来源:http ://docs.aws.amazon.com/athena/latest/ug/known-limitations.html


推荐阅读