带有数据流的 Apache Beam:WriteToBigQuery 的标志 'ignore_unknown_columns' 不起作用

Apache Beam with Dataflow: flag 'ignore_unknown_columns' for WriteToBigQuery not working

我正在使用 Apache Beam(Python SDK 版本 2.37.0)和 Google Dataflow 构建流式传输管道,以将我通过 Pubsub 收到的一些数据写入 BigQuery。

我处理数据并以这样的字典表示的行结束:

{'val1': 17.4, 'val2': 40.8, 'timestamp': 1650456507, 'NA_VAL': 'table_name'}

然后我想使用 WriteToBigQuery 将值插入我的 table。

但是,我的 table 只有 val1val2timestamp 列。因此,NA_VAL 应该被忽略。根据我对 docs 的理解,这应该可以通过设置 ignore_unknown_columns=True.

但是,当 运行 Dataflow 中的管道时,我仍然收到错误,并且没有值被插入 table:

There were errors inserting to BigQuery. Will not retry. Errors were [{'index': 0, 'errors': [{'reason': 'invalid', 'location': 'NA_VAL', 'debugInfo': '', 'message': 'no such field: NA_VAL.'}]}]

我试过像这样的简单作业配置

rows | beam.io.WriteToBigQuery(
            table='PROJECT:DATASET.TABLE',
            ignore_unknown_columns=True)

以及这些参数

rows | beam.io.WriteToBigQuery(
            table='PROJECT:DATASET.TABLE',
            ignore_unknown_columns=True,
            create_disposition=beam.io.BigQueryDisposition.CREATE_NEVER,
            write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND,
            method='STREAMING_INSERTS',
            insert_retry_strategy='RETRY_NEVER')

问题:我是否遗漏了一些阻止管道工作的东西?有没有人有同样的问题and/or解决方案?

不幸的是你被虫子咬了。这被报告为 https://issues.apache.org/jira/browse/BEAM-14039 and fixed by https://github.com/apache/beam/pull/16999。版本 2.38.0 将包含此修复程序。该版本的验证今天刚刚结束,因此应该很快就会可用。