Hive可以将avro字节反序列化为提供的模式吗?

时间:2017-10-11 23:50:10

标签: hadoop hive hdfs avro

我有avro文件加载到Hive但我的文件是二进制文件。 应该使用什么解串器来获取二进制avro?

我不希望hive中的二进制数据,而是解码的二进制数据。

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

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

当我使用上面的命令表创建时,数据被加载但是当我从表中执行select *时,我得到以下错误:

失败,异常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}
]
}

1 个答案:

答案 0 :(得分:0)

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

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

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