首页 > 解决方案 > 使用 BigQuery Client() 类时出现错误 TypeError: Object of type set is not JSON serializable

问题描述

当我尝试使用 Client() 运行 BigQuery 时,出现 JSON 不可序列化错误。这是我的代码片段:

client = Client()
query = { "select * from `abc`"}
query_job = client.query(query, location= US)
results = query_job.result().dataframe()

现在,当我尝试它时会抛出错误。请提供任何帮助。

标签: pythongoogle-bigquery

解决方案


基于Bigquery python 示例,您需要传递query值 asSTRING并且传递的是 JSON 类型

例如:

from google.cloud import bigquery
client = bigquery.Client()

query = (
    "SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` "
    'WHERE state = "TX" '
    "LIMIT 100"
)
query_job = client.query(
    query,
    location="US",
) 

for row in query_job:
    assert row[0] == row.name == row["name"]

希望能帮助到你。


推荐阅读