Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery select multiple key values

With a custom event in Firebase exported to BigQuery, multiple key-value params can exist within it. I can't seem to figure out how to select more than just one of these using "standard SQL".

How would I project both msg and succes values (string_value and int_value) into one record

like image 998
Casper Bang Avatar asked May 04 '17 20:05

Casper Bang


1 Answers

Let's say that you wanted to select the string_value that corresponds with firebase_event_origin and the int_value associated with firebase_screen_id for all control_reading events. You could express the query as:

#standardSQL
SELECT
  (SELECT param.value.string_value
   FROM UNNEST(event_dim.params) AS param
   WHERE param.key = 'firebase_event_origin') AS firebase_event_origin,
  (SELECT param.value.int_value
   FROM UNNEST(event_dim.params) AS param
   WHERE param.key = 'firebase_screen_id') AS firebase_screen_id
FROM `your_dataset.your_table_*`
CROSS JOIN UNNEST(event_dim) AS event_dim
WHERE _TABLE_SUFFIX BETWEEN '20170501' AND '20170503' AND
  event_dim.name = 'control_reading';
like image 67
Elliott Brossard Avatar answered Nov 01 '22 04:11

Elliott Brossard