将AVDL文件转换为Apache的某些东西,可以解析Avro Python软件包
我想做的就是将.AVDL文件解析为Python。我想利用来自Python内部的信息。
根据文档,Apache的Python软件包不处理.AVDL文件。我需要使用他们的avro-tools
将.AVDL文件转换为它知道如何解析的东西。
根据
java -jar avro-tools.jar idl src/test/idl/input/namespaces.avdl /tmp/namespaces.avpr
不清楚的是如何使用Python软件包来解释这些数据。我尝试了一些简单的东西...
schema = avro.schema.parse(open("my.avpr", "rb").read())
但是生成了错误:
SchemaParseException: No "type" property:
我相信avro.schema.parse
旨在解析.AVSC文件(?)。但是,目前尚不清楚如何使用avro-tools
将我的.AVDL转换为.avsc。有可能吗?
我猜想有很多我缺少的作品,并且还不了解所有这些文件的目的。
似乎.AVPR是一个JSON文件(?),因此我可以自己阅读和解释,但是我希望会有一个Python软件包可以帮助我导航数据。
谁能对此提供一些见解?谢谢。
What I would like to be able to do is take an .avdl file and parse it into python. I would like to make use of the information from within python.
According to the documentation, Apache's python package does not handle .avdl files. I need to use their avro-tools
to convert the .avdl file into something it does know how to parse.
According to the documentation at https://avro.apache.org/docs/current/idl.html, I can convert a .avdl file into a .avpr file with the following command:
java -jar avro-tools.jar idl src/test/idl/input/namespaces.avdl /tmp/namespaces.avpr
I ran through my .avdl file through Avro-tools, and it produced an .avpr file.
What is unclear is how I can use the python package to interpret this data. I tried something simple...
schema = avro.schema.parse(open("my.avpr", "rb").read())
but that generates the error:
SchemaParseException: No "type" property:
I believe that avro.schema.parse
is designed to parse .avsc files (?). However, it is unclear how I can use avro-tools
to convert my .avdl into .avsc. Is that possible?
I am guessing there are many pieces I am missing and do not quite understand (yet) what the purpose of all of these files are.
It does appear that an .avpr is a JSON file (?) so I can just read and interpret it myself, but I was hoping that there would be a python package that would assist me in navigating the data.
Can anyone provide some insights into this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是使用avro-tools.jar使用
indl2schemata
命令,为其提供可以编写.AVSC文件的输出目录。然后可以阅读.AVSC文件Avro Python软件包。例如:
The answer is to use the
idl2schemata
command with avro-tools.jar, providing it with an output directory to which it can write the .avsc files. The .avsc files can then be read AVRO python package.For example: