我已將 AVRO 文件(帶有 JSON 負載)從 Microsoft Azure 下載到我的 Windows 10 計算機:然后通過 pip 安裝 python 3.8.5 和 avro 1.10.0 我嘗試運行以下腳本:import os, avrofrom avro.datafile import DataFileReader, DataFileWriterfrom avro.io import DatumReader, DatumWriterreader = DataFileReader(open("48.avro", "rb"), DatumReader())for d in reader: print(d)reader.close()不幸的是,腳本沒有打印任何內容。然后我四處搜索并嘗試添加如下所示的架構:schema_str = """{ "type" : "record", "name" : "EventData", "namespace" : "Microsoft.ServiceBus.Messaging", "fields" : [ { "name" : "SequenceNumber", "type" : "long" }, { "name" : "Offset", "type" : "string" }, { "name" : "EnqueuedTimeUtc", "type" : "string" }, { "name" : "SystemProperties", "type" : { "type" : "map", "values" : [ "long", "double", "string", "bytes" ] } }, { "name" : "Properties", "type" : { "type" : "map", "values" : [ "long", "double", "string", "bytes", "null" ] } }, { "name" : "Body", "type" : [ "null", "bytes" ] } ]}"""schema = avro.schema.parse(schema_str)reader = DataFileReader(open("48.avro", "rb"), DatumReader(schema, schema))for d in reader: print(d)reader.close()但這并沒有幫助,仍然沒有打印任何內容。雖然我期待會打印字典對象列表......
1 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
正如 OneCricketeer 建議使用 PySpark 讀取 EventHub 生成的 avro 文件。此處,PySpark:反序列化 eventhub 捕獲 avro 文件中包含的 Avro 序列化消息就是這樣的示例。
添加回答
舉報
0/150
提交
取消