I have a table in BigQuery with the following structure:
datetime | event | value
==========================
1 | add | 1
---------+--------+-------
2 | remove | 1
---------+--------+-------
6 | add | 2
---------+--------+-------
8 | add | 3
---------+--------+-------
11 | add | 4
---------+--------+-------
23 | remove | 3
---------+--------+-------
I'm trying to build a view which adds a list column to each row containing the current state of the array. The array will never contain duplicate items. This should be the result:
datetime | event | value | list
===================================
1 | add | 1 | [1]
---------+--------+-------+--------
2 | remove | 1 | []
---------+--------+-------+--------
6 | add | 2 | [2]
---------+--------+-------+--------
8 | add | 3 | [2,3]
---------+--------+-------+--------
11 | add | 4 | [2,3,4]
---------+--------+-------+--------
23 | remove | 3 | [2,4]
---------+--------+-------+--------
I tried using analytic functions but it didn't work out. The api to work with arrays is quite limited. I think I would succeed if I could use recursive WITH clauses, unfortunately this is not possible in BigQuery.
I'm using BigQuery with standard SQL enabled.

3, for example, and then oneremoveevent for3? Are all occurrences of3removed, or just one? - Elliott Brossard