-
Optimizing BigQuery Google Analytics Sample: Handling repetitive nested elements with CASE WHEN logic
I’m getting a bit hung up on this part of our SQL query:
CASE WHEN type=’EVENT’ THEN product.v2ProductName[SAFE_OFFSET(1)] ELSE NULL END.
When we exclude this bit, everything seems to be smooth sailing. However, once we add it, we run into trouble. I’ve tried various fixes, like unnesting within the case statement (even though “orig” is already unnested in our temporary table), or using OFFSET and SAFE_OFFSET with or without UNNEST, but no luck yet.
Just as a side note, “product” doesn’t need to be unnested (it’s the same deal for “page” and “eventInfo”). Here’s our current version of the SQL query:
(Then proceed to mention the SQL query.)
As for the output, I’m hoping for a frame with these fields: visitor_id, last_visit, last_hit, type, page, product, action, and label. And this should be generated for every user who hasn’t made a purchase.
Just FYI, the hits.product.v2ProductName field is nested and repetitive. However, when the event type is ‘EVENT’, it’s not repetitive (unlike when the event type is social or page). As such, theoretically, I shouldn’t have to use OFFSET to select a particular element from the list, although I’ve tried with and without it all the same. If you have any suggestions, I’d be grateful. Thanks!
Log in to reply.