BigQuery API:400 语法错误:预期关键字 JOIN 但得到“)”
Posted
技术标签:
【中文标题】BigQuery API:400 语法错误:预期关键字 JOIN 但得到“)”【英文标题】:BigQuery API: 400 Syntax error: Expected keyword JOIN but got ")" 【发布时间】:2019-01-13 12:19:08 【问题描述】:我正在尝试通过 bq python api(在标准 sql 模式下)运行查询,但出现错误:
400 语法错误:预期的关键字 JOIN 但在 [1:621] 得到“)”
这是我的代码:
from google.cloud import bigquery
import pandas as pd
client = bigquery.Client.from_service_account_json(r'/Users/dmitrij/Desktop/api-*****.json')
QUERY2=("select date,pagePath,prev_page_path,hits.eventInfo.eventCategory,hits.eventInfo.eventAction,hits.eventInfo.eventLabel, COUNT(CONCAT(prev_page_path,pagePath,hits.eventInfo.eventAction,hits.eventInfo.eventLabel)) as count from (SELECT hits.page.pagePath AS pagePath, LAG(hits.page.pagePath) OVER (PARTITION BY fullVisitorId, visitStartTime ORDER BY hits.hitNumber) AS prev_page_path, date, hits.eventInfo.eventCategory, hits.eventInfo.eventAction, hits.eventInfo.eventLabel FROM (TABLE_DATE_RANGE([api-open-broker.150225190.ga_sessions_], DATE_ADD(CURRENT_TIMESTAMP(), -8, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY')))")
query_job2 = client.query(QUERY2)
df_prevp = query_job2.to_dataframe()
QUERY2 在 Legacy SQL Syntaxes 中,但如果将代码放在 like 之前:
job_config = bigquery.QueryJobConfig()
job_config.use_legacy_sql = True
我有一个错误:
400 在第 1 行第 621 列遇到“”。 期待: ")" ...
这是QUERY2:
select date,pagePath,prev_page_path,hits.eventInfo.eventCategory,hits.eventInfo.eventAction,hits.eventInfo.eventLabel, COUNT(CONCAT(prev_page_path,pagePath,hits.eventInfo.eventAction,hits.eventInfo.eventLabel)) as count
from
(SELECT
hits.page.pagePath AS pagePath,
LAG(hits.page.pagePath) OVER (PARTITION BY fullVisitorId, visitStartTime ORDER BY hits.hitNumber) AS prev_page_path,
date,
hits.eventInfo.eventCategory,
hits.eventInfo.eventAction,
hits.eventInfo.eventLabel
FROM
(TABLE_DATE_RANGE([api-open-broker.150225190.ga_sessions_],
DATE_ADD(CURRENT_TIMESTAMP(), -8, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY')))
WHERE
hits.type="EVENT"
AND hits.eventInfo.eventCategory LIKE "%Title_Name_Podpisat%" )
where prev_page_path is not null
group by pagePath,prev_page_path,date,hits.eventInfo.eventCategory,hits.eventInfo.eventAction,hits.eventInfo.eventLabel
如何避免这个错误?
【问题讨论】:
【参考方案1】:这个错误
400 在第 1 行第 621 列遇到“”。期待:“)”...
意味着您没有设置 job_config 和 BQ 尝试将您的查询作为标准 sql 运行,我希望看到类似这样的内容:
query_job2 = client.query(QUERY2, job_config=job_config)
另一种选择是在代码开头使用#LegacySql
【讨论】:
job_config = bigquery.QueryJobConfig() job_config.use_legacy_sql = True QUERY2=....... query_job2 = client.query(QUERY2, job_config=job_config) df_prevp = query_job2.to_dataframe()跨度> 在这种情况下,我遇到了错误:400 在第 1 行第 621 列遇到“以上是关于BigQuery API:400 语法错误:预期关键字 JOIN 但得到“)”的主要内容,如果未能解决你的问题,请参考以下文章
语法错误:预期输入结束,但在 bigquery 中的 [11:1] 处出现关键字 INSERT 错误
BigQuery SQL 语法错误 FOR 函数(“语法错误:预期的”)“但在 [7:18] 获得关键字 FOR”)
BigQuery SQL语法错误FOR函数(“语法错误:预期的”)”,但在[7:18]处获得了关键字FOR)
400 Bad Request 错误尝试从云存储加载 bigquery 表