【发布时间】:2018-07-31 18:08:09
【问题描述】:
我们的环境使用 Python 2.7 和 BigQuery 库 0.27.0。
要提交的查询是由
加载的 JSON 字符串的一部分json.loads(json_blob)
然后从键中提取查询的值:
query_str = json_blob["sql_command"]
打印query_str 会得到以下值:
('query_str: ', '" select distinct id from my_table where step_count > 3 and lower(name) = \'test\') "')
当脚本提交查询执行如下:
job = self.bq_client.run_async_query(job_id, query_str, udf_resources=udf_obj, query_parameters=query_params)
BigQuery 作业返回错误,当我使用 https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get 上的 job_id 查找作业信息时,我看到实际执行的查询如下:
select distinct id from my_table where step_count \u003e 3 and lower(name) = 'test')
我已经阅读了编码/解码并尝试了它们,并且没有区别。
有没有办法可以将从 json_blob (query_str = json_blob["sql_command"]) 检索到的 query_str 转换为真正的字符串?我们知道,当我们将此类查询定义为字符串(在脚本中硬编码而不是从 JSON blob 中的键检索)时,查询会成功执行,例如。
query_str = """select distinct id from my_table where step_count > 3 and lower(name) = 'test')"""
非常感谢任何建议。
【问题讨论】:
标签: python python-2.7 google-bigquery