Below is a structure that I am using. It is Google Analytic events coming from firebase.
I need to AND
across the params array and return only one of the param values with the key of 'eventData'. While at the same time I need to limit the query by two other objects (having keys values of 'peripheral' and 'eventType') found in the same params array.
I'm using Legacy SQL but willing to work with something else. I looked and played with FLATTEN but that didn't seem to give me what I was looking for in the end. A query example may make more sense.
SELECT event_dim.params.value.int_value -- this needs to come from the eventData object
FROM
[table]
where event_dim.name = 'EPILOG_BAT'
AND event_dim.timestamp_micros > 1529423373498009
-- AND event_dim.params contains (key='peripheral', string_value = 'CA5D6D4C-9B4C-9BB1-03CF-5A8BCD7651FE')
-- AND event_dim.params contains (key='eventType', string_value = 'V')
order by event_dim.timestamp_micros ,
event_dim.params.key
the row I would expect to get would be 4105
Data:
"event_dim": [
{{
"date": "20180620",
"name": "EPILOG_BAT",
"params": [
{
"key": "eventData",
"value": {
"string_value": null,
"int_value": "4105",
"float_value": null,
"double_value": null
}
},
{
"key": "peripheral",
"value": {
"string_value": "CA5D6D4C-9B4C-9BB1-03CF-5A8BCD7651FE",
"int_value": null,
"float_value": null,
"double_value": null
}
},
{
"key": "eventTime",
"value": {
"string_value": null,
"int_value": "1529499380000",
"float_value": null,
"double_value": null
}
},
{
"key": "eventType",
"value": {
"string_value": "V",
"int_value": null,
"float_value": null,
"double_value": null
}
},
{
"key": "firmwareVersion",
"value": {
"string_value": "0.8.6\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
"int_value": null,
"float_value": null,
"double_value": null
}
}
],
"timestamp_micros": "1529478561132285",
"previous_timestamp_micros": "1529478560856003",
"value_in_usd": null
},}