[英]If the avro schema is stored with the data, why does the java avro api need me to supply a schema file?
在某些情況下,Microsoft Azure 決定以 avro 格式轉儲數據。 從我的角度來看,有問題的數據只是 json 記錄。 所以,我只想從 avro 文件中返回我的 json 數據。
我正在研究如何“反序列化”avro 數據,以及此處的示例:
https://avro.apache.org/docs/1.8.1/gettingstartedjava.html
提出索賠:
Data in Avro is always stored with its corresponding schema, meaning we can always read a serialized item regardless of whether we know the schema ahead of time.
不幸的是,這些示例確實需要提前了解架構:
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema);
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(file, datumReader);
我一定遺漏了一些東西,我只想要我的數據(文本/json)格式,脫離 avro。 有沒有辦法在不知道架構的情況下做到這一點? avro 不能從文件本身中讀取它嗎?
既然已經有了獲取 json 的工具,為什么還要寫代碼呢?
java -jar avro-tools-1.8.2.jar tojson data.avro > output.json
http://central.maven.org/maven2/org/apache/avro/avro-tools/1.8.2/avro-tools-1.8.2.jar
否則,您的文件有一個架構,您必須在讀取文件內容之前先提取它,這正是上述工具的源代碼所做的
您需要提供讀者的架構,以便 Avro 可以執行架構解析
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.