Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select multiple custom Firebase event parameters in BigQuery?

I exported Firebase events to BigQuery and now I'm trying to select two parameters from a certain event. Here is the query for selecting one parameter:

select event_dim.params.value.int_value as level_id
from [com_company_appname_ANDROID.app_events_20161210]
where event_dim.name = "level_replays_until_first_victory" and  event_dim.params.key = "level_id"

Both parameters are int values, name of the first parameter is level_id, and the second parameter is count. What I would like is to show is level_id in first column and count in second column.

like image 849
Luka Maške Avatar asked Dec 11 '16 19:12

Luka Maške


1 Answers

Below will work with BigQuery Standard SQL

SELECT 
  (SELECT params.value.int_value FROM x.params 
                                 WHERE params.key = 'level_id') AS level_id,
  (SELECT params.value.int_value FROM x.params 
                                 WHERE params.key = 'count') AS count
FROM `com_company_appname_ANDROID.app_events_20161210`, UNNEST(event_dim) AS x
WHERE x.name  = 'level_replays_until_first_victory'

See also Migrating from legacy SQL in case if you are stuck with Legacy SQL

like image 77
Mikhail Berlyant Avatar answered Sep 30 '22 05:09

Mikhail Berlyant