如何修复:Python 代码中的 BigQuery 查询
How to fix: BigQuery query in Python code
我尝试在 BigQuery 查询中使用变量。语法错误。可能是什么问题?
我尝试了带有 ''' 的字符串块,但结果相同。
QUERY = ('WITH activity_data AS ('
'SELECT user_pseudo_id, event_timestamp, event_name,'
'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'
'3600*1000*1000*24*1 AS one_interval_micros'
'FROM `events_*`'
"WHERE _table_suffix BETWEEN \'"+ table_start_str "\' AND \'"+ table_end_str1 "\'"
'AND event_name IN ("z_Added","y_Added","x_Added")'
'AND user_pseudo_id IN ('
'SELECT user_pseudo_id'
'FROM `events_*`'
"WHERE _table_suffix BETWEEN \'"+ table_start_str"\' AND \'"+ table_end_str2"\'"
'AND event_name = "first_open"'
'AND event_timestamp BETWEEN UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'", "Europe/Budapest"))'
'AND UNIX_MICROS(TIMESTAMP("'+ cohort_date_end_str'", "Europe/Budapest"))'
"""
)
)
...
"""
第 18 行语法错误:Colab 中的小箭头指向行尾的破折号。
LINE 18:
'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'
错误截图:
https://image.prntscr.com/image/rpuNg96iRom9-n7qaTvILA.png
您在 + cohort_date_str
之后还缺少 +
。 + table_start_str
相同。等等
我尝试在 BigQuery 查询中使用变量。语法错误。可能是什么问题?
我尝试了带有 ''' 的字符串块,但结果相同。
QUERY = ('WITH activity_data AS ('
'SELECT user_pseudo_id, event_timestamp, event_name,'
'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'
'3600*1000*1000*24*1 AS one_interval_micros'
'FROM `events_*`'
"WHERE _table_suffix BETWEEN \'"+ table_start_str "\' AND \'"+ table_end_str1 "\'"
'AND event_name IN ("z_Added","y_Added","x_Added")'
'AND user_pseudo_id IN ('
'SELECT user_pseudo_id'
'FROM `events_*`'
"WHERE _table_suffix BETWEEN \'"+ table_start_str"\' AND \'"+ table_end_str2"\'"
'AND event_name = "first_open"'
'AND event_timestamp BETWEEN UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'", "Europe/Budapest"))'
'AND UNIX_MICROS(TIMESTAMP("'+ cohort_date_end_str'", "Europe/Budapest"))'
"""
)
)
...
"""
第 18 行语法错误:Colab 中的小箭头指向行尾的破折号。
LINE 18:
'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'
错误截图: https://image.prntscr.com/image/rpuNg96iRom9-n7qaTvILA.png
您在 + cohort_date_str
之后还缺少 +
。 + table_start_str
相同。等等