【问题标题】:How to infer schema in the Avro header in apache_beam python?如何在 apache_beam python 的 Avro 标头中推断模式?
【发布时间】:2022-11-11 01:43:38
【问题描述】:

我有一个 AVRO 文件,该文件在标题中有架构。我正在尝试使用 apache_beam Pyhotn SDK 从标头中获取架构。但无法得到。任何帮助或方向都将得到应用。

【问题讨论】:

    标签: google-cloud-dataflow apache-beam avro


    【解决方案1】:

    您可以考虑使用这两种方法来运行光束管道以使用 Python 从 avro 文件中推断模式。

    选项1:

    p = beam.Pipeline(options=pipeline_options)
    
    schema = avro.schema.parse(open("avro.avsc", "rb").read())
    
    records = p | 'Read from Avro' >> ReadFromAvro(known_args.input)
    
    # Write the file
    records | 'Write to Avro' >> WriteToAvro(known_args.output, schema=schema, file_name_suffix='.avro')
    
    # Run the pipeline
    result = p.run()
    result.wait_until_finish()
    

    选项 2:使用 python with 关键字执行管道:

    schema = avro.schema.parse(open("avro.avsc", "rb").read())
    
    with beam.Pipeline(options=pipeline_options) as p:
        records = p | ReadFromAvro(known_args.input)
        records | WriteToAvro(known_args.output, schema=schema, file_name_suffix='.avro')
    

    有关更多信息,您可以参考此document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 1970-01-01
      • 2019-10-11
      • 2011-10-21
      • 2018-11-18
      • 1970-01-01
      相关资源
      最近更新 更多