[英]BigQuery schema change not propagated prior to running next step in Apache Beam pipeline
我正在使用 apache 梁在一个管道中实现 3 个步骤。
我注意到在步骤 2 中更新架构之前执行了步骤 3,并且我收到错误消息“读取数据时出错,错误消息:JSON 表遇到太多错误,放弃”。 但是,如果我再次运行相同的代码,则可以成功保存数据。 看起来在完整架构之前执行的第一次 step3 已在 step2 中更新。
我是 Apache 光束的新手。 你能帮忙吗? 谢谢。 我的代码附在下面。
dim_seller_etl_executor = (
p1
| "read" >> beam.io.ReadFromMongoDB(uri='mongodb:///',
db='',
coll='',
bucket_auto=True,
extra_client_params={"username": "",
"password": ""})
| "transform" >> beam.Map(transform_doc)
| 'save' >> beam.io.Write((beam.io.WriteToBigQuery("table_id",
schema=table_schema_for_beam,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED,
write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND)))
)
def transform_doc(document):
global table_schema_for_beam
global column_name_type
new_columns = []
for name, value in document.items():
if name not in column_name_type:
# some ways to get the column type
new_columns.append((name, column_type))
else:
column_type = column_name_type[name]
data[name] = document[name] if document[name] is not None else None
# if new columns appear, update the schema in bigquery and the schema used in beam.io.WriteToBigQuery
if new_columns:
bigquery_schema.add_columns(new_columns)
table_schema_for_beam, column_name_type = bigquery_schema.get_table_schema_for_beam()
return data
我可以看到两个问题:
table_schema_for_beam
变量在管道构建期间进行评估。 在管道运行时改变这些变量可能会产生未知的影响,或者根本没有影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.