如何在Windows 10上使用avro-python3解析文件?
我已将一个AVRO文件(带有JSON有效负载)从Microsoft Azure下载到我的Windows 10计算机: 然后通过pip安装python 3.8.5和avro 1.10.0,我尝试运行以下脚本:如何在Windows 10上使用avro-python3解析文件?,python,python-3.x,avro,Python,Python 3.x,Avro,我已将一个AVRO文件(带有JSON有效负载)从Microsoft Azure下载到我的Windows 10计算机: 然后通过pip安装python 3.8.5和avro 1.10.0,我尝试运行以下脚本: import os, avro from avro.datafile import DataFileReader, DataFileWriter from avro.io import DatumReader, DatumWriter reader = DataFileReader(op
import os, avro
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
reader = 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()
但这并没有帮助,仍然没有打印任何内容
当我期待字典对象的列表会被打印出来的时候
更新:
我在会议上得到的答复是,avro-python3已被弃用
但我的问题仍然与原来的avro坚持,没有打印
更新2:
我必须道歉-我使用的avro文件不包含任何有用的数据。我感到困惑的原因是,一位同事在为我测试时使用了同名的不同文件
现在,我在不同的avro文件上尝试了avro和fastavro模块,两个模块都工作了。我还将介绍PySpark。正如OneCricketeer建议的那样,使用PySpark读取EventHub生成的avro文件。这里是一个这样的例子。正如OneCricketeer建议的那样,使用PySpark读取EventHub生成的avro文件。这里有一个这样的例子。fwiw,
fastavro
应该可以更好地工作。您也可以使用PySpark直接从Azure/wasbwiw读取,fastavro
应该可以更好地工作。您也可以使用PySpark直接从Azure/WASB读取