如何在avro架构中指定时间戳

时间:2018-06-04 11:47:02

标签: java hive avro

我正在尝试在1520200800049中转换此值Avro。这是我的模式中字段的规范,顺便说一下是union模式:

{
 "name" : "TimestampField"
 "type" : ["null",{
    "type":"long",
    "logicalType":"timestamp-millis"
 }]
}

这是我得到的错误:

Caused by: org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"long","logicalType":"timestamp-millis"}]: 1520200800049 
    at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:740) 
    at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:205) 
    at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:123) 
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:75) 
    at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:166) 
    at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:156) 
    at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:118) 
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:75) 
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:62) 
    at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:302)

当我将架构更改为:

{
 "name" : "TimestampField"
 "type" : ["null" , "long"]
}

有效。但这不是重点。我希望将timestamp转换为Hive目的。

2 个答案:

答案 0 :(得分:1)

Hive 1.1支持它。详情here

答案 1 :(得分:0)

检查Hive Server的类路径中的Avro JAR。它可能是1.7不支持逻辑类型(https://avro.apache.org/docs/1.7.4/spec.html