Creating sample Avro data for bytes type

落爺英雄遲暮 提交于 2020-05-28 07:16:46

问题


I am trying to create a sample .avro file containing bytes as type and decimal as logicalType, But the avro file when loaded to hive table results in a different value. What could be the reason?

schema.avsc:

{
  "type" : "record",
  "name" : "example",
  "namespace" : "com.xyz.avro",
  "fields" : [ {
    "name" : "cost",
    "type" : {
      "type" : "bytes",
      "logicalType" : "decimal",
      "precision" : 38,
      "scale" : 10
    }
  }]
}

data.json:

{ "cost" : "0.0" }

Converted to .avro using avro-tools:

java -jar avro-tools-1.8.2.jar fromjson --schema-file schema.avsc data.json > data.avro

After loading data.avro and querying the hive table:

hive> select cost from tmp_cost;
OK
0.0003157552

A similar question on SO: create json representation for decimal logical type and byte types for avro schema

来源:https://stackoverflow.com/questions/60623764/creating-sample-avro-data-for-bytes-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!