Conditional incrementing in BigQuery
<p>I have a data table like this:</p>

<pre><code>user_id  event_time
1        1456812346
1        1456812350
1        1456812446
1        1456812950
1        1456812960
</code></pre>

<p>Now, I am trying to define a 'session_id' for the user based on the event_time. If the events come after a lag of 180 seconds, the events are considered as from new session. So, I would like an output similar to:</p>

<pre><code>user_id  event_time  session_id
1        1456812346   1
1        1456812350   1
1        1456812446   1
1        1456812950   2
1        1456812960   2
</code></pre>

<p>The session is incremented at 4th row as the time is 504 secs after 3rd row and thus more than the threshold of 180 secs.</p>

<p>In Mysql, I could just declare a variable and then increment it conditionally. As variable creation is not supported in BigQuery, is there an alternate way to achieve this?</p>