Google bigquery 如何在使用Airflow加载到bigQuery时忽略未知列?
我正在使用Google bigquery 如何在使用Airflow加载到bigQuery时忽略未知列?,google-bigquery,airflow,Google Bigquery,Airflow,我正在使用GoogleCloudStorageToBigQueryOperator将数据从Google存储加载到bigQuery 可能Json文件的列数比我定义的要多。在这种情况下,我希望加载作业继续-只需忽略此无法识别的列。 我尝试使用ignore\u unknown\u value参数,但没有任何区别 我的接线员: def dc(): return [ { "name": "id", "type": "INTEGER", "mo
GoogleCloudStorageToBigQueryOperator将数据从Google存储加载到bigQuery
可能Json文件的列数比我定义的要多。在这种情况下,我希望加载作业继续-只需忽略此无法识别的列。
我尝试使用ignore\u unknown\u value
参数,但没有任何区别
我的接线员:
def dc():
return [
{
"name": "id",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "storeId",
"type": "INTEGER",
"mode": "NULLABLE"
},
...
]
gcs_to_bigquery_st = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_to_BigQuery_stage',
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template_st,
source_format='NEWLINE_DELIMITED_JSON',
source_objects=[gcs_export_uri_template],
ignore_unknown_values = True,
schema_fields=dc(),
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows = 1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
gcs_to_bigquery_st = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_to_BigQuery_stage',
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template_st,
source_format='NEWLINE_DELIMITED_JSON',
source_objects=[gcs_export_uri_template],
ignore_unknown_values = True,
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows = 1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
错误:
读取数据时出错,错误消息:第行JSON解析错误
从位置0开始:无此类字段:shippingService。“
这是真的。shippingService不存在,不会将其添加到表中
我怎样才能解决这个问题
编辑:
从运算符中删除了schema\u fields=dc()
:
def dc():
return [
{
"name": "id",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "storeId",
"type": "INTEGER",
"mode": "NULLABLE"
},
...
]
gcs_to_bigquery_st = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_to_BigQuery_stage',
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template_st,
source_format='NEWLINE_DELIMITED_JSON',
source_objects=[gcs_export_uri_template],
ignore_unknown_values = True,
schema_fields=dc(),
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows = 1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
gcs_to_bigquery_st = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_to_BigQuery_stage',
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template_st,
source_format='NEWLINE_DELIMITED_JSON',
source_objects=[gcs_export_uri_template],
ignore_unknown_values = True,
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows = 1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
仍然给出相同的错误。
这可不是闹着玩的。。它有忽略未知值的命令:(我能想到的唯一原因是您可能正在使用气流1.9。此功能是在气流1.10中添加的
但是,您可以通过添加src\u fmt\u configs={'ignoreUnknownValues':True}
在Airflow 1.9中使用它,如下所示:
gcs_to_bigquery_st = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_to_BigQuery_stage',
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template_st,
source_format='NEWLINE_DELIMITED_JSON',
source_objects=[gcs_export_uri_template],
src_fmt_configs={'ignoreUnknownValues': True},
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows = 1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
Thx!缺乏在文档版本之间移动的能力确实是个问题!我建议使用ReadTheDocs