【问题标题】:How to get the record name defined in avro schema with python?如何使用 python 获取在 avro 模式中定义的记录名称?
【发布时间】:2017-02-01 17:05:32
【问题描述】:

我在 C# 中使用 Avro 序列化数据。 然后我用 Python 反序列化它。假设我有以下架构:

{
  "type": "record",
  "name": "ClassXY",
  "fields" : [{"name": "x", "type": "double"}]
}

如果我的记录是“ClassXY”类型,我如何在 python 端检查? 我可以以某种方式访问​​“名称”的值(ClassXY)吗?

【问题讨论】:

  • 您要检查 dict["type"] == "ClassXY" 还是需要检查某个类名是否为 "ClassXY" ?我不清楚。
  • 我想检查 dict['name'] == "ClassXY".

标签: c# python avro


【解决方案1】:
message_buf = io.BytesIO(message)
reader = avro.datafile.DataFileReader(message_buf, avro.io.DatumReader())
schema_name = reader.datum_reader.reader_schema.name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多