Python BigQuery DataLab的查询参数格式
大家好,这里是社区 所以我一直在尝试让这个参数化查询在DataLab笔记本上运行。由于我计划执行此类参数的多个赋值查询,因此无法使用%%bq execute语法。相反,我一直在尝试使用.executequery\u params=query\u params,但我无法确定query\u params数据的适当格式 为了完整起见,这是我的简化版本: %%bq查询-n myq 挑选* 从“某张桌子”` 其中某个_字段=@field 查询参数=[{'name':'field','type':'STRING','value':'POTATO'}] myq.executequery\u params=query\u params.result.to\u dataframe 我认为query_params参数必须是一个列表,并认为每个元素都应该是一个带有这些键的字典,因为 尽管如此,当我在DataLab笔记本上执行此操作时,会出现一个错误,指示缺少参数类型。请参阅下面的部分错误跟踪Python BigQuery DataLab的查询参数格式,python,google-bigquery,google-cloud-datalab,Python,Google Bigquery,Google Cloud Datalab,大家好,这里是社区 所以我一直在尝试让这个参数化查询在DataLab笔记本上运行。由于我计划执行此类参数的多个赋值查询,因此无法使用%%bq execute语法。相反,我一直在尝试使用.executequery\u params=query\u params,但我无法确定query\u params数据的适当格式 为了完整起见,这是我的简化版本: %%bq查询-n myq 挑选* 从“某张桌子”` 其中某个_字段=@field 查询参数=[{'name':'field','type':'STRI
/usr/local/envs/py3env/lib/python3.5/site-packages/google/datalab/bigquery/_query.py in execute_async(self, output_options, sampling, context, query_params)
268 allow_large_results=output_options.allow_large_results,
269 table_definitions=self.data_sources,
--> 270 query_params=query_params)
271 except Exception as e:
272 raise e
/usr/local/envs/py3env/lib/python3.5/site-packages/google/datalab/bigquery/_api.py in jobs_insert_query(self, sql, table_name, append, overwrite, dry_run, use_cache, batch, allow_large_results, table_definitions, query_params)
200 query_config['queryParameters'] = query_params
201
--> 202 return google.datalab.utils.Http.request(url, data=data, credentials=self.credentials)
203
204 def jobs_query_results(self, job_id, project_id, page_size, timeout, start_index=0):
/usr/local/envs/py3env/lib/python3.5/site-packages/google/datalab/utils/_http.py in request(url, args, data, headers, method, credentials, raw_response, stats)
156 return json.loads(str(content, encoding='UTF-8'))
157 else:
--> 158 raise RequestException(response.status, content)
159 except ValueError:
160 raise Exception('Failed to process HTTP response.')
RequestException: HTTP request failed: Missing query parameter type
你知道我在这里遗漏了什么吗?我到处搜索,试图找到这个查询参数的合适格式,但到目前为止运气不好
谢谢你的帮助。我终于让它基于 预期的格式是
query_params = [
{
'name': 'field',
'parameterType': {'type': 'STRING'},
'parameterValue': {'value': field}
}
]