问题
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