Google bigquery 如何在Python中对大查询插入\u行\u json进行单元测试

Google bigquery 如何在Python中对大查询插入\u行\u json进行单元测试,google-bigquery,Google Bigquery,我有一个Python插入到下面这样的大查询表中,如何模拟insert语句并进行单元测试?先谢谢你 def write_to_big_query(bq_project, bq_dataset, bq_table_name, messagePayload, messageAttributes, eventId): if all(k in json_data.keys() for k in [‘example1, ‘example2’, ‘example3’]): # streaming i

我有一个Python插入到下面这样的大查询表中,如何模拟insert语句并进行单元测试?先谢谢你

def write_to_big_query(bq_project, bq_dataset, bq_table_name, messagePayload, messageAttributes, eventId):

if all(k in json_data.keys() for k in [‘example1, ‘example2’, ‘example3’]):
    # streaming insert
    errors = bq_client.insert_rows_json(bigquery.DatasetReference(bq_project, bq_dataset).table(bq_table_name), [json_data], ignore_unknown_values=True)
else:
    errors = ['missing example1, example2, example3 in message payload.']

if errors:
    write_bq_status = False

    for e in errors:
        logger.warning("Error loading message {} into BigQuery: {}", eventId, str(e))

        json_data_error = {
            "pubsub_attributes": metadata["pubsub_attributes"],
            "pubsub_messageid": metadata["pubsub_messageid"],
            "raw_json": metadata["raw_json"],
            "ingested_ts": json_data["ingested_ts"],
            "ingest_error": str(e)
        }
     

return write_bq_status