Problems / URL Path Parsing / Editorial
regexp_extract(url, 'https?://[^/]+/([^/?#]+)', 1)
https?
[^/]+
[^/?#]+
/
?
#
https://shop.example.com
/?ref=ad
regexp_extract
coalesce(nullif(section, ''), 'home')
count(*)
views
views DESC, section
The no-match behavior is the trap: both DuckDB and Spark return '' from regexp_extract when the pattern fails, so a plain coalesce never fires. You need nullif(..., '') (SQL) or an explicit F.when(col == '', ...) (PySpark) to route homepage traffic into the home bucket.
''
coalesce
nullif(..., '')
F.when(col == '', ...)
home
Solve URL Path Parsing yourself →