问题
I am fairly new to StandardSQL, and wanted to export Raw BigQuery log-data for users that installed on a given date (1st June 2017) with first 3-week's session data on and after install-date (D0-D20).
#StandardSQL
SELECT user_dim.first_open_timestamp_micros, user_dim.app_info.app_instance_id, event_dim.date, event_dim.name, event_dim.timestamp_micros, event_dim.previous_timestamp_micros
FROM `your_table_id.app_events_*`
WHERE _TABLE_SUFFIX BETWEEN '20170601' AND '20170621' AND
(SELECT user_dim.first_open_timestamp_micros
FROM UNNEST(user_dim) AS user
WHERE user.first_open_timestamp_micros BETWEEN 1496275200000 AND 1496361600000);
I am only getting the following output: "Values referenced in UNNEST must be arrays. UNNEST contains expression of type STRUCT". My initial question was: How would I convert this into an array, to give me the appropriate output ?
Update after Mikhail's answer:
The following query executed, but did not give any data as output. I know there should be users that should show up, because if I preview the actual table (view screenshot), I see values that exist in the table that should be part of the output (but is not).
#standardSQL
SELECT
user_dim.first_open_timestamp_micros,
user_dim.app_info.app_instance_id,
event.date, event.name,
event.timestamp_micros,
event.previous_timestamp_micros
FROM `your_table_id.app_events_*`, UNNEST(event_dim) AS event
WHERE _TABLE_SUFFIX BETWEEN '20170601' AND '20170621'
AND user_dim.first_open_timestamp_micros BETWEEN 1496275200000 AND 1496361600000
LIMIT 10;
Screenshot of the actual table:
Converting the timestamps, shows that the above session should indeed show up in the middle of the 2 user_dim.first_open_timestamp_micros-results, but does not...
1496275200000 Converted: Assuming that this timestamp is in milliseconds: GMT: Thursday, June 1, 2017 12:00:00 AM Your time zone: Thursday, June 1, 2017 2:00:00 AM GMT+02:00 DST
1496353126947000 Converted: Assuming that this timestamp is in microseconds (1/1,000,000 second): GMT: Thursday, June 1, 2017 9:38:46.947 PM Your time zone: Thursday, June 1, 2017 11:38:46.947 PM GMT+02:00 DST
1496361600000 Converted: Assuming that this timestamp is in milliseconds: GMT: Friday, June 2, 2017 12:00:00 AM Your time zone: Friday, June 2, 2017 2:00:00 AM GMT+02:00 DST
Question:
- Am I missing something, why would that value not show up in the output ?
回答1:
Try below
I assumed - user_dim
is record
, and event_dim
is record, repeated
#standardSQL
SELECT
user_dim.first_open_timestamp_micros,
user_dim.app_info.app_instance_id,
event.date, event.name,
event.timestamp_micros,
event.previous_timestamp_micros
FROM `your_table_id.app_events_*`, UNNEST(event_dim) AS event
WHERE _TABLE_SUFFIX BETWEEN '20170601' AND '20170621'
AND user_dim.first_open_timestamp_micros BETWEEN 1496275200000 AND 1496361600000
来源:https://stackoverflow.com/questions/45920753/raw-bigquery-log-data-for-1st-day-installers