Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带记录的BigQuery python插入(\w client.insert\u行)_Python_Google Cloud Platform_Insert_Google Bigquery - Fatal编程技术网

带记录的BigQuery python插入(\w client.insert\u行)

带记录的BigQuery python插入(\w client.insert\u行),python,google-cloud-platform,insert,google-bigquery,Python,Google Cloud Platform,Insert,Google Bigquery,我目前正试图在BQ数据集中插入一行 我想为此使用Client.insert_row()函数 我为一个没有“Record”类型字段的简单模式启动并运行了所有内容。 但是,当我向模式中添加“Record”类型的字段时,我不知道如何在insert_row()函数中定义它 我的模式: 我的代码: client = bigquery.Client( credentials=credentials, project=credentials.project_id, ) dataset_r

我目前正试图在BQ数据集中插入一行

我想为此使用Client.insert_row()函数

我为一个没有“Record”类型字段的简单模式启动并运行了所有内容。 但是,当我向模式中添加“Record”类型的字段时,我不知道如何在insert_row()函数中定义它

我的模式:

我的代码:

client = bigquery.Client(
    credentials=credentials,
    project=credentials.project_id,
)

dataset_ref = client.dataset('channel_data')

table_ref = dataset_ref.table('test')
table = client.get_table(table_ref)  # API call

rows_to_insert = [{"test1":"a","test2":"b","test3":"c","record":{"1":"d","2":"e"}},]

errors = client.insert_rows_json(table, rows_to_insert)  # API request
assert errors == []
我尝试了许多不同版本的行插入:

rows_to_insert = [{"test1":"a","test2":"b","test3":"c","record":["d","e"]},]
rows_to_insert = [{"test1":"a","test2":"b","test3":"c","record.1":"d","record.2":"e"}},]
它们似乎都不起作用,我在网上找不到任何关于如何做到这一点的信息。 以前有人这样做过吗

将其作为JSON插入很重要,因为有时会丢失一些值。 我知道你可以把所有的东西都放进一个列表,然后像这样转移

rows_to_insert = [("a", "b", "c", ["d", "e"])]

但这不是我的选择

插入它们的正确方法如下:

rows_to_insert = [{"test1":"a","test2":"b","test3":"c","record":{"r1":"d","r2":"e"}}]

记录字段本身有一个字典作为条目,特定字段作为键/值

使用insert_rows_json API时的一个观察结果。我使用这个API插入json行,如下所示:
result=bq\u client.insert\u rows\u json(table=bq\u table,json\u rows=json\u rows,skip\u invalid\u rows=False,ignore\u unknown\u values=False)print(result)
。如果json行和bq表模式之间存在不匹配,那么我不会将所有错误返回到同一个结果列表中。我期待json插入的所有错误列表。如果多次运行同一语句,则在每个API调用中会出现不同的模式错误。有什么解决办法吗?