How to select multiple custom Firebase event parameters in BigQuery?

Luka Maške picture Luka Maške · Dec 11, 2016 · Viewed 8.6k times · Source

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.

Answer

Mikhail Berlyant picture Mikhail Berlyant · Dec 11, 2016

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