I'm trying to perform a very simple query for Firebase events stored in Google BigQuery but I´m not able to find a way to do it.
In the Android app, I´m logging an event like this:
Bundle params = new Bundle();
params.putInt("productID", productId);
params.putInt(FirebaseAnalytics.Param.VALUE, value);
firebaseAnalytics.logEvent("productEvent", params);
So, in BigQuery I have something like this:
___________________ _______________________ ____________________________ | event_dim.name | event_dim.params.key | event_dim.params.int_value | |___________________|_______________________|____________________________| | productEvent | productID | 25 | | |_______________________|____________________________| | | value | 1253 | |___________________|_______________________|____________________________|
When I get the data from this table I get two rows:
___________________ _______________________ ____________________________ |event_dim.name | event_dim.params.key | event_dim.params.int_value | |___________________|_______________________|____________________________| | productEvent | productID | 25 | | productEvent | value | 12353 |
But what I really need is a SELECT clause from this table to get the data as below:
___________________ _____________ _________ | name | productID | value | |___________________|_____________|_________| | productEvent | 25 | 12353 |
Any idea or suggestion?
Definition. The UNNEST function takes an ARRAY and returns a table with a row for each element in the ARRAY.
To convert an ARRAY into a set of rows, also known as "flattening," use the UNNEST operator. UNNEST takes an ARRAY and returns a table with a single row for each element in the ARRAY . Because UNNEST destroys the order of the ARRAY elements, you may wish to restore order to the table.
BigQuery is a Google Cloud tool that lets you run super-fast queries of large datasets. You can export all of your raw, unsampled events from Google Analytics to BigQuery, and then use a SQL-like syntax to query that data.
You can pivot the values into columns like this
SELECT
event_dim.name as name,
MAX(IF(event_dim.params.key = "productID", event_dim.params.int_value, NULL)) WITHIN RECORD productID,
MAX(IF(event_dim.params.key = "value", event_dim.params.int_value, NULL)) WITHIN RECORD value,
FROM [events]
In case you want to generate this command using SQL, see this solution: Pivot Repeated fields in BigQuery
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With