【发布时间】:2016-09-19 09:39:19
【问题描述】:
我正在尝试将 BigQuery Standard SQL 与 Python API 结合使用,但无法执行在 WEB UI 中成功运行的查询。
基本上,我正在拆分一个字符串,然后使用 OFFSET 关键字来获取特定索引处的值。如下:
CASE WHEN t.depth = 1 THEN '' WHEN t.depth = 2 THEN '' WHEN t.depth = 3 THEN '' WHEN t.depth = 4 THEN '' WHEN t.depth = 5 THEN '' WHEN t.depth = 6 THEN t.curr WHEN t.depth = 7 THEN SPLIT(t.ancestry,'/')[OFFSET(6)] ELSE '' END AS level7,
CASE WHEN t.depth = 1 THEN '' WHEN t.depth = 2 THEN '' WHEN t.depth = 3 THEN '' WHEN t.depth = 4 THEN '' WHEN t.depth = 5 THEN t.curr WHEN t.depth = 6 THEN SPLIT(t.ancestry,'/')[OFFSET(5)] WHEN t.depth = 7 THEN SPLIT(t.ancestry,'/')[OFFSET(5)] ELSE '' END AS level6,
以上代码在 WEB UI 中运行没有问题,而使用 Python API 并设置useLegacySQL = False,我收到以下错误
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/*************
returned "Encountered " "]" "[OFFSET(6)] "" at line 7, column 217. Was expecting: "END" ...">
感谢任何帮助。
【问题讨论】:
-
我现在试过了,它对我有用。你能在这里添加你的代码吗?