如何在python中提取avro文件的架构 [英] How to extract schema for avro file in python

查看:130
本文介绍了如何在python中提取avro文件的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python Avro库( https://pypi.python.org/pypi/avro )以读取由JAVA生成的AVRO文件.由于架构已经嵌入到avro文件中,为什么我需要指定架构文件?有没有办法自动将其提取?

I am trying to use the Python Avro library (https://pypi.python.org/pypi/avro) to read a AVRO file generated by JAVA. Since the schema is already embedded in the avro file, why do I need to specify a schema file? Is there a way to extract it automatically?

找到了另一个名为fastavro的软件包( https://pypi.python.org/pypi/fastavro )可以提取avro模式.手册是否通过设计在python arvo软件包中指定了架构文件?非常感谢.

Found another package called fastavro(https://pypi.python.org/pypi/fastavro) can extract avro schema. Is the manual specifying schema file in python arvo package by design? Thank you very much.

推荐答案

我使用python 3.4和Avro软件包1.7.7

I use python 3.4 and Avro package 1.7.7

对于架构文件,请使用:

For schema file use:

reader = avro.datafile.DataFileReader(open('file_name.avro',"rb"),avro.io.DatumReader())
schema = reader.meta
print(schema) 

这篇关于如何在python中提取avro文件的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆