【发布时间】: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
如何避免这个错误?
【问题讨论】:
标签: pandas api google-bigquery