首页 > 解决方案 > GBQ:SchemaField REPEATED 模式写入空数组

问题描述

我正在尝试向 gbq 编写一个简单的数据框。其中一个字段是数组,所以我尝试使用 REPEATED 模式。但似乎没有任何内容写入数组

df = pd.DataFrame(
    {
        'my_string': ['a', 'b', 'c'],
        'my_int64': [1, 2, 3],
        'my_float64': [4.0, 5.0, 6.0],
        'my_timestamp': [
            pd.Timestamp("1998-09-04T16:03:14"),
            pd.Timestamp("2010-09-13T12:03:45"),
            pd.Timestamp("2015-10-02T16:00:00")
        ],
        'my_array': [
            [1,2,3],
            [4,5,6],
            [7,8,9]
        ]
    }
)
# client = bigquery.Client()
table_id = 'junk.pshah2_new_table'
# Since string columns use the "object" dtype, pass in a (partial) schema
# to ensure the correct BigQuery data type.
job_config = bigquery.LoadJobConfig(schema=[
    bigquery.SchemaField("my_string", "STRING"),
    bigquery.SchemaField("my_array", "INTEGER","REPEATED"),
])

job = client.load_table_from_dataframe(
    df, table_id, job_config=job_config
)

# Wait for the load job to complete.
job.result()

在GBQ我根本找不到my_array写的 在此处输入图像描述

我在这里做错了吗?

标签: google-cloud-platformgoogle-bigquery

解决方案


推荐阅读