People who started using Google Analytics real-time streaming into bigquery may come across a query conflict while calling ga_realtime_sessions table with data range filter condition, e.g.,
when we execute the below query
SELECT * FROM
TABLE_DATE_RANGE([project:dataset.ga_realtime_sessions_], CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP())
LIMIT 1000
We end up with error message
Query Failed
The reason is because of both real-time table and views have same naming pattern
Realtime Table: project:dataset.ga_realtime_sessions_20180929
Realtime View: project:dataset.ga_realtime_sessions_view_20180929
In addition, the real-time view is available in Legacy SQL, so we cannot use it for Standard SQL queries, to overcome this it is good to save below query as view to get realtime data for today.
SELECT * FROM
`project.dataset.ga_realtime_sessions_2*`
WHERE
CONCAT('2', CAST(_TABLE_SUFFIX AS string)) = FORMAT_DATE("%Y%m%d", CURRENT_DATE())
AND exportKey IN (
SELECT
exportKey
FROM (
SELECT
exportKey,
exportTimeUsec,
MAX(exportTimeUsec) OVER (PARTITION BY visitKey) AS maxexportTimeUsec
FROM
`project.dataset.ga_realtime_sessions_2*`
WHERE
CONCAT('2', CAST(_TABLE_SUFFIX AS string)) = FORMAT_DATE("%Y%m%d", CURRENT_DATE()))
WHERE
exportTimeUsec >= maxexportTimeUsec)
No comments:
Post a Comment