Discussion about this post

User's avatar
Lars's avatar

Great article! = ) Coming from Snowflake I've missed a lot of functionality in BQ, but your ideas here fill many of those gaps!

I particularly find the "Accessing items in Arrays"-part very valuable. For the other parts there might be good alternative approaches and I suggest some below (haven't done any performance assessments though...)

-- Virtual Columns

SELECT

DATE_TRUNC(date_column, MONTH) AS month,

SUM(sales) OVER (ORDER BY month) AS cumulative_sales

FROM some_table

-- ...and rows

SELECT

COALESCE(user_region_code, user_country_code, 'GLOBAL'),

COUNT(DISTINCT user_id) AS users

FROM some_table

GROUP BY ROLLUP (user_country_code, user_region_code)

-- Consistent Column Selection

SELECT DISTINCT

user_id,

FIRST_VALUE(device_type) OVER(ORDER BY device_id) AS device_type,

FIRST_VALUE(device_os) OVER(ORDER BY device_id) AS device_os,

COUNT(1) OVER() AS events

FROM some_table

Expand full comment
2 more comments...

No posts