diff --git a/views/bigquery.go b/views/bigquery.go index ee92988..c357d05 100644 --- a/views/bigquery.go +++ b/views/bigquery.go @@ -155,7 +155,7 @@ func (bq *bigqueryHandler) QueryViewsEvents(ctx context.Context, spec QuerySpec) func buildViewsEventsQuery(table string, spec QuerySpec) (string, []interface{}, error) { query := squirrel.Select( "countif(play_intent) as view_count", - "sum(playtime_ms) / 60000.0 as playtime_mins"). + "ifnull(sum(playtime_ms), 0) / 60000.0 as playtime_mins"). From(table). Where("account_id = ?", spec.Filter.UserID). Limit(maxBigQueryResultRows + 1) diff --git a/views/bigquery_test.go b/views/bigquery_test.go index 5bca6d4..10d318b 100644 --- a/views/bigquery_test.go +++ b/views/bigquery_test.go @@ -23,7 +23,7 @@ func TestCallsBigQueryClient(t *testing.T) { _, err := bq.QueryViewsEvents(context.Background(), QuerySpec{}) require.ErrorContains(err, "dry-run") - require.Equal("SELECT countif(play_intent) as view_count, sum(playtime_ms) / 60000.0 as playtime_mins "+ + require.Equal("SELECT countif(play_intent) as view_count, ifnull(sum(playtime_ms), 0) / 60000.0 as playtime_mins "+ "FROM bq_events WHERE account_id = ? LIMIT 10001", receivedQuery) }