Skip to content

Instantly share code, notes, and snippets.

@drewbanin
Created April 29, 2020 23:54
Show Gist options
  • Save drewbanin/0c769cbec1534723200c70807ec55d40 to your computer and use it in GitHub Desktop.
Save drewbanin/0c769cbec1534723200c70807ec55d40 to your computer and use it in GitHub Desktop.
select
collector_tstamp,
se_category,
se_action,
parse_json(se_action)
from raw.snowplow.event
where collector_tstamp > '2020-04-28'
and app_id = 'community.getdbt.com'
order by 1 desc;
;
with dogs as (
select parse_json($$
{
"animals": {
"dogs": {
"labrador": {
"name": "Labrador",
"weight": 23
},
"boxer": {
"name": "boxer",
"weight": 55
},
},
"cats": {
"short hair": {
"name": "short hair",
"weight": 10
},
"scottish fold": {
"name": "scottish fold",
"weight": 6
},
},
"birds": {
"parrot": {},
"owl": {
"name": "owl",
},
},
"fish": {},
}
}$$) as dogs
)
select
level1.key as animal,
level2.key::string as name_from_label,
level2.value:name::string as name_from_dict,
level2.value:weight::int as weight
from dogs,
lateral flatten (input => dogs:animals, outer => true) level1,
lateral flatten (input => level1.value, outer => true) level2
order by 1,2,3,4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment