Skip to content

Commit

Permalink
fix(hogql): support non-string funnel breakdowns (#22330)
Browse files Browse the repository at this point in the history
* fix(hogql): support non-string funnel breakdowns

* Update query snapshots

* Update query snapshots

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
thmsobrmlr and github-actions[bot] authored May 16, 2024
1 parent ad3d6d7 commit 5dc6a68
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@
# name: TestFunnelBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen
'''
/* cohort_calculation: */
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -1084,7 +1084,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -1115,7 +1115,7 @@
# name: TestFunnelBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step
'''
/* cohort_calculation: */
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -1202,7 +1202,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
if(ifNull(equals(step_0, 1), 0), prop_basic, []) AS prop_0,
if(ifNull(equals(step_1, 1), 0), prop_basic, []) AS prop_1,
prop_1 AS prop,
Expand Down Expand Up @@ -1237,7 +1237,7 @@
# ---
# name: TestFunnelBreakdown.test_funnel_step_multiple_breakdown_snapshot
'''
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), ''), ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -1321,7 +1321,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(equals(e.event, 'buy'), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), ''), ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -1351,7 +1351,7 @@
# ---
# name: TestFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
LEFT JOIN
Expand Down Expand Up @@ -1475,7 +1475,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -1506,7 +1506,7 @@
# ---
# name: TestFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events_poe_v2
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
LEFT OUTER JOIN
Expand Down Expand Up @@ -1636,7 +1636,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -1667,7 +1667,7 @@
# ---
# name: TestFunnelGroupBreakdown.test_funnel_breakdown_group
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -1798,7 +1798,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serializer version: 1
# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_current_url
'''
SELECT [if(empty(replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', ''))] AS value,
SELECT [if(empty(replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', ''))] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -85,7 +85,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[if(empty(replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', ''))] AS prop_basic,
[if(empty(replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', ''))] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -115,7 +115,7 @@
# ---
# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname
'''
SELECT [if(empty(replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', ''))] AS value,
SELECT [if(empty(replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', ''))] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -199,7 +199,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[if(empty(replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', ''), ''), '[\\/?#]*$', ''))] AS prop_basic,
[if(empty(replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$pathname'), ''), 'null'), '^"|"$', '')), ''), '[\\/?#]*$', ''))] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serializer version: 1
# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen
'''
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -84,7 +84,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -114,7 +114,7 @@
# ---
# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step
'''
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -199,7 +199,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
if(ifNull(equals(step_0, 1), 0), prop_basic, []) AS prop_0,
if(ifNull(equals(step_1, 1), 0), prop_basic, []) AS prop_1,
prop_1 AS prop,
Expand Down Expand Up @@ -234,7 +234,7 @@
# ---
# name: TestFunnelStrictStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot
'''
SELECT [ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), ''), ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), '')] AS value,
SELECT [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -317,7 +317,7 @@
if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
if(equals(e.event, 'buy'), 1, 0) AS step_1,
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
[ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), ''), ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), '')] AS prop_basic,
[ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -347,7 +347,7 @@
# ---
# name: TestStrictFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
LEFT JOIN
Expand Down Expand Up @@ -471,7 +471,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -502,7 +502,7 @@
# ---
# name: TestStrictFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events_poe_v2
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
LEFT OUTER JOIN
Expand Down Expand Up @@ -632,7 +632,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down Expand Up @@ -663,7 +663,7 @@
# ---
# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group
'''
SELECT ifNull(e__group_0.properties___industry, '') AS value,
SELECT ifNull(toString(e__group_0.properties___industry), '') AS value,
count(*) AS count
FROM events AS e
INNER JOIN
Expand Down Expand Up @@ -794,7 +794,7 @@
if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
if(equals(e.event, 'buy'), 1, 0) AS step_2,
if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2,
ifNull(e__group_0.properties___industry, '') AS prop_basic,
ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,
prop_basic AS prop,
argMinIf(prop, timestamp, isNotNull(prop)) OVER (PARTITION BY aggregation_target) AS prop_vals
FROM events AS e
Expand Down
Loading

0 comments on commit 5dc6a68

Please sign in to comment.