简体   繁体   English

Avro append 记录不存在模式并保存为 avro 文件?

[英]Avro append a record with non-existent schema and save as an avro file?

I have just started using Avro and I'm using fastavro library in Python.我刚刚开始使用 Avro,我正在 Python 中使用 fastavro 库。

  1. I prepared a schema and saved data with this one.我准备了一个模式并用这个保存了数据。
  2. Now, I need to append new data (JSON response from an API call ) and save it with a non-existent schema to the same avro file.现在,我需要 append 新数据(来自 API 调用的 JSON 响应)并将其与不存在的模式一起保存到同一个 avro 文件中。 How shall I proceed to add the JSON response with no predefined schema and save it to the same Avro file?我应该如何继续添加没有预定义架构的 JSON 响应并将其保存到同一个 Avro 文件?

Thanks in advance.提前致谢。

Avro files, by definition, already have a schema within them.根据定义,Avro 文件中已经有一个模式。

You could read that schema first, then continue to append data, or you can read entire file into memory, then append your data, then overwrite the file.您可以先读取该架构,然后继续读取 append 数据,或者您可以将整个文件读取到 memory,然后读取 append 数据,然后覆盖文件。

Each option require you to convert the JSON into Avro (or at least a Python dict), though.不过,每个选项都要求您将 JSON 转换为 Avro(或至少 Python 字典)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM