【问题标题】:Can Hive deserialize avro bytes to the schema provided?Hive 可以将 avro 字节反序列化为提供的架构吗?
【发布时间】:2018-03-23 18:41:46
【问题描述】:

我有要加载到 Hive 的 avro 文件,但我的文件是二进制文件。 应该使用什么反序列化器来让二进制 avro 进入 hive?

我不想要 hive 中的二进制数据,而是解码后的二进制数据。

这就是我创建表格的方式。

创建表 kst7 行格式SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe' 存储为输入格式 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat' 输出格式 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat' TBL 属性 ( 'avro.schema.url'='pathtoavsc.avsc');

当我使用上面的命令创建表时,会加载数据,但是当我从表中选择 * 时出现以下错误:

异常 java.io.IOException:org.apache.avro.AvroTypeException 失败:找到字节,期待联合

avsc 文件:

{
"namespace": "com.nimesh.tripod.avro.enrichment",
"type": "record",
"name": "EnrichmentData",
"fields": [
    {"name": "rowKey", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
    {"name": "ownerGuid", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
    {"name": "autotagsEnrichment", "type": ["bytes", "null", {
                                                        "namespace": "com.nimesh.tripod.avro.enrichment",
                                                        "type": "record",
                                                        "name": "AutotagEnrichment",
                                                        "fields": [
                                                            {"name": "version", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
                                                            {"name": "autotags", "type": ["null", {"type": "array", "items": {
                                                                                                                                 "namespace": "com.nimesh.tripod.avro.enrichment",
                                                                                                                                 "type": "record",
                                                                                                                                 "name": "Autotag",
                                                                                                                                 "fields": [
                                                                                                                                     {"name": "tag", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
                                                                                                                                     {"name": "score", "type": ["null", "double"], "default": null}
                                                                                                                                 ]
                                                                                                                             }}], "default": null}
                                                        ]
                                                    }], "default": null},
    {"name": "colorEnrichment", "type": ["bytes","null", {
                                                     "namespace": "com.nimesh.tripod.avro.enrichment",
                                                     "type": "record",
                                                     "name": "ColorEnrichment",
                                                     "fields": [
                                                         {"name": "version", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
                                                         {"name": "color", "type": ["null", {"type": "array", "items": {
                                                                                                                           "namespace": "com.nimesh.tripod.avro.enrichment",
                                                                                                                           "type": "record",
                                                                                                                           "name": "Color",
                                                                                                                           "fields": [
                                                                                                                               {"name": "color", "type": ["null", {"type":"string","avro.java.string":"String"}], "default": null},
                                                                                                                               {"name": "score", "type": ["null", "double"], "default": null}
                                                                                                                           ]
                                                                                                                       }}], "default": null}
                                                     ]
                                                 }], "default": null}
]
}

【问题讨论】:

    标签: hadoop hive hdfs avro


    【解决方案1】:

    我认为您正在寻找 SERDEPROPERTIES 而不是 TBLPROPERTIES

    ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
    WITH SERDEPROPERTIES ('avro.schema.url'='pathtoschema.avsc')
    

    否则,请尝试选择单个字段,直到找到导致错误的字段,然后检查 AVSC 映射到 Hive 表中的类型。

    【讨论】:

    • 运气不好。实际上我的 avro 文件有元组而不是 json 行。元组是 (string, string, json, json)。
    • 你能在问题中分享你的 avsc 吗?
    • 我在描述中添加了avsc文件。我的 avro 也是一个元组(字符串、字符串、)。当我为我的 avro 文件执行 getschema 时,我得到字符串、字符串、字节、字节
    • 听起来你有字节,而不是你的数据中包含的 Avro 复杂类型。旁注:对于默认值,您最好先列出空值;假设该字段可以为空
    • 是的,忽略字节。我的数据中包含 avro 复杂类型。添加字节只是我试图摆脱这个问题的一种尝试。
    猜你喜欢
    • 2021-12-18
    • 2022-08-22
    • 2021-03-07
    • 1970-01-01
    • 2021-06-26
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多