将AVDL文件转换为Apache的某些东西,可以解析Avro Python软件包

发布于 2025-01-22 19:51:52 字数 732 浏览 0 评论 0原文

我想做的就是将.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2025-01-29 19:51:52

答案是使用avro-tools.jar使用indl2schemata命令,为其提供可以编写.AVSC文件的输出目录。然后可以阅读.AVSC文件Avro Python软件包。

例如:

java -jar avro-tools.jar idl2schemata src/test/idl/input/namespaces.avdl /tmp/

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:

java -jar avro-tools.jar idl2schemata src/test/idl/input/namespaces.avdl /tmp/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文