Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(hogql): fix keyword line-splitting in pretty_print_in_tests (#61337)

Robbie0fca8b2f8143
diff --git a/posthog/hogql/functions/test/__snapshots__/test_action.ambr b/posthog/hogql/functions/test/__snapshots__/test_action.ambr
index 2de00ab235e9..0dc357a56665 100644
--- a/posthog/hogql/functions/test/__snapshots__/test_action.ambr
+++ b/posthog/hogql/functions/test/__snapshots__/test_action.ambr
@@ -2,30 +2,22 @@
# name: TestAction.test_matches_action_with_alias
'''
-- ClickHouse
-
SELECT
e.event AS event
-
FROM
events AS e
-
WHERE
and(equals(e.team_id, 99999), equals(e.event, %(hogql_val_0)s), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0))
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
event
-
FROM
events AS e
-
WHERE
and(equals(event, 'RANDOM_TEST_ID::UUID'), equals(e.properties.$current_url, 'https://posthog.com/feedback/123?vip=1'))
-
LIMIT 100
'''
# ---
diff --git a/posthog/hogql/functions/test/__snapshots__/test_cohort.ambr b/posthog/hogql/functions/test/__snapshots__/test_cohort.ambr
index 7345415eeef5..ac0d881be78a 100644
--- a/posthog/hogql/functions/test/__snapshots__/test_cohort.ambr
+++ b/posthog/hogql/functions/test/__snapshots__/test_cohort.ambr
@@ -2,7 +2,6 @@
# name: TestCohort.test_in_cohort_dynamic
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -15,7 +14,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events
WHERE and(in(person_id, (
@@ -30,7 +28,6 @@
# name: TestCohort.test_in_cohort_dynamic_other_team_in_project
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -43,7 +40,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events
WHERE and(in(person_id, (
@@ -58,7 +54,6 @@
# name: TestCohort.test_in_cohort_static
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -69,7 +64,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events
WHERE in(person_id, (
@@ -82,7 +76,6 @@
# name: TestCohort.test_in_cohort_strings
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -93,7 +86,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events
WHERE in(person_id, (
diff --git a/posthog/hogql/test/__snapshots__/test_query.ambr b/posthog/hogql/test/__snapshots__/test_query.ambr
index eb9c920bcbcc..07a15f8fc920 100644
--- a/posthog/hogql/test/__snapshots__/test_query.ambr
+++ b/posthog/hogql/test/__snapshots__/test_query.ambr
@@ -2,7 +2,6 @@
# name: TestQuery.test_clickhouse_timestamp_handling
'''
-- ClickHouse
-
SELECT if(not(empty(events__exception_issue_override.issue_id)), events__exception_issue_override.issue_id, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s)) AS id, count(DISTINCT events.uuid) AS occurrences, count(DISTINCT nullIf(events.`$session_id`, %(hogql_val_3)s)) AS sessions, count(DISTINCT events.distinct_id) AS users, max(toTimeZone(events.timestamp, %(hogql_val_4)s)) AS last_seen, min(toTimeZone(events.timestamp, %(hogql_val_5)s)) AS first_seen, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_6)s, toStartOfHour(toTimeZone(events.timestamp, %(hogql_val_7)s)), toStartOfHour(now64(6, %(hogql_val_8)s)))), x), range(24))) AS volumeDay, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_9)s, toStartOfDay(toTimeZone(events.timestamp, %(hogql_val_10)s)), toStartOfDay(now64(6, %(hogql_val_11)s)))), x), range(31))) AS volumeMonth, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_12)s, toStartOfHour(toTimeZone(events.timestamp, %(hogql_val_13)s)), toStartOfHour(now64(6, %(hogql_val_14)s)))), x), range(168))) AS customVolume
FROM events LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(error_tracking_issue_fingerprint_overrides.issue_id), error_tracking_issue_fingerprint_overrides.version), 1) AS issue_id, error_tracking_issue_fingerprint_overrides.fingerprint AS fingerprint
@@ -12,29 +11,30 @@
HAVING ifNull(equals(tupleElement(argMax(tuple(error_tracking_issue_fingerprint_overrides.is_deleted), error_tracking_issue_fingerprint_overrides.version), 1), 0), 0)
SETTINGS optimize_aggregation_in_order=1) AS events__exception_issue_override ON equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), events__exception_issue_override.fingerprint)
WHERE and(equals(events.team_id, 99999), and(equals(events.event, %(hogql_val_15)s), isNotNull(if(not(empty(events__exception_issue_override.issue_id)), events__exception_issue_override.issue_id, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_16)s), ''), 'null'), '^"|"$', ''), %(hogql_val_17)s))), or(and(greater(toTimeZone(events.timestamp, %(hogql_val_18)s), parseDateTime64BestEffort(%(hogql_val_19)s, 6, %(hogql_val_20)s)), less(toTimeZone(events.timestamp, %(hogql_val_21)s), parseDateTime64BestEffort(%(hogql_val_22)s, 6, %(hogql_val_23)s))), and(greater(toTimeZone(events.timestamp, %(hogql_val_24)s), toDateTime(%(hogql_val_25)s, %(hogql_val_26)s)), less(toTimeZone(events.timestamp, %(hogql_val_27)s), toDateTime64(%(hogql_val_28)s, 6, %(hogql_val_29)s))))))
- GROUP BY if(not(empty(events__exception_issue_override.issue_id)), events__exception_issue_override.issue_id, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_30)s), ''), 'null'), '^"|"$', ''), %(hogql_val_31)s)) ORDER BY occurrences DESC
- LIMIT 51 OFFSET 0
+ GROUP BY if(not(empty(events__exception_issue_override.issue_id)), events__exception_issue_override.issue_id, accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_30)s), ''), 'null'), '^"|"$', ''), %(hogql_val_31)s))
+ ORDER BY occurrences DESC
+ LIMIT 51
+ OFFSET 0
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT issue_id AS id, count(DISTINCT uuid) AS occurrences, count(DISTINCT nullIf($session_id, '')) AS sessions, count(DISTINCT distinct_id) AS users, max(timestamp) AS last_seen, min(timestamp) AS first_seen, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('hour', toStartOfHour(timestamp), toStartOfHour(now()))), x), range(24))) AS volumeDay, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('day', toStartOfDay(timestamp), toStartOfDay(now()))), x), range(31))) AS volumeMonth, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('hour', toStartOfHour(timestamp), toStartOfHour(now()))), x), range(168))) AS customVolume
FROM events
WHERE and(equals(event, '$exception'), isNotNull(issue_id), or(and(greater(timestamp, toDateTime('2025-02-10 23:53:03.175952+02:30')), less(timestamp, toDateTime('2025-02-11 23:53'))), and(greater(timestamp, toDateTime('2025-02-12 23:53:03')), less(timestamp, toDateTime('2025-02-13 23:53:03.175952')))))
- GROUP BY issue_id ORDER BY occurrences DESC
- LIMIT 51 OFFSET 0
+ GROUP BY issue_id
+ ORDER BY occurrences DESC
+ LIMIT 51
+ OFFSET 0
'''
# ---
# name: TestQuery.test_hogql_arrays
'''
-- ClickHouse
-
SELECT [1, 2, 3], [10, 11, 12][1]
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT [1, 2, 3], [10, 11, 12][1]
LIMIT 100
'''
@@ -42,7 +42,6 @@
# name: TestQuery.test_hogql_groupby_unnecessary_ifnull
'''
-- ClickHouse
-
SELECT toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS timestamp, count() AS cnt
FROM events
WHERE and(equals(events.team_id, 99999), greaterOrEquals(timestamp, addDays(today(), -10)))
@@ -52,7 +51,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT toDate(timestamp) AS timestamp, count() AS cnt
FROM events
WHERE greaterOrEquals(timestamp, addDays(today(), -10))
@@ -64,13 +62,11 @@
# name: TestQuery.test_hogql_lambdas
'''
-- ClickHouse
-
SELECT arrayMap(x -> multiply(x, 2), [1, 2, 3]) AS `arrayMap(x -> multiply(x, 2), [1, 2, 3])`, 1
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT arrayMap(x -> multiply(x, 2), [1, 2, 3]), 1
LIMIT 100
'''
@@ -88,7 +84,8 @@
SELECT major_versions.major_version AS major_version, count() AS user_count, round(divide(multiply(100, count()), sum(count()) OVER ()), 2) AS percentage
FROM major_versions
WHERE in(major_versions.major_version, tuple(%(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s))
- GROUP BY major_versions.major_version ORDER BY major_versions.major_version ASC
+ GROUP BY major_versions.major_version
+ ORDER BY major_versions.major_version ASC
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
@@ -103,14 +100,14 @@
SELECT major_version, count() AS user_count, round(divide(multiply(100, count()), sum(count()) OVER ()), 2) AS percentage
FROM major_versions
WHERE in(major_version, tuple('17', '18', '26'))
- GROUP BY major_version ORDER BY major_version ASC
+ GROUP BY major_version
+ ORDER BY major_version ASC
LIMIT 100
'''
# ---
# name: TestQuery.test_hogql_query_filters
'''
-- ClickHouse
-
SELECT events.event AS event, events.distinct_id AS distinct_id
FROM events
WHERE and(equals(events.team_id, 99999), equals(events.distinct_id, %(hogql_val_0)s), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0))
@@ -118,7 +115,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, distinct_id
FROM events
WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), equals(properties.index, '4'))
@@ -137,7 +133,6 @@
# name: TestQuery.test_hogql_query_filters.2
'''
-- ClickHouse
-
SELECT events.event AS event, events.distinct_id AS distinct_id
FROM events
WHERE and(equals(events.team_id, 99999), equals(events.distinct_id, %(hogql_val_0)s), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0), less(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC'))))
@@ -145,7 +140,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, distinct_id
FROM events
WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), and(equals(properties.index, '4'), less(timestamp, toDateTime('2020-01-02 00:00:00.000000')), greaterOrEquals(timestamp, toDateTime('2020-01-01 00:00:00.000000'))))
@@ -164,7 +158,6 @@
# name: TestQuery.test_hogql_query_filters_alias
'''
-- ClickHouse
-
SELECT e.event AS event, e.distinct_id AS distinct_id
FROM events AS e
WHERE and(equals(e.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), 0))
@@ -172,7 +165,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, distinct_id
FROM events AS e
WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')
@@ -182,7 +174,6 @@
# name: TestQuery.test_hogql_query_filters_session_date_range
'''
-- ClickHouse
-
SELECT sessions.session_id AS session_id, sessions.`$entry_current_url` AS `$entry_current_url`
FROM (
SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, nullIf(nullIf(argMinMerge(raw_sessions.entry_url), %(hogql_val_0)s), %(hogql_val_1)s) AS `$entry_current_url`, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_2)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7
@@ -194,7 +185,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT session_id, $entry_current_url
FROM sessions
WHERE and(less($start_timestamp, toDateTime('2024-07-06 00:00:00.000000')), greaterOrEquals($start_timestamp, toDateTime('2024-07-04 00:00:00.000000')))
@@ -213,7 +203,6 @@
# name: TestQuery.test_hogql_query_session_filters
'''
-- ClickHouse
-
SELECT sessions.session_id AS session_id, sessions.`$entry_current_url` AS `$entry_current_url`
FROM (
SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, nullIf(nullIf(argMinMerge(raw_sessions.entry_url), %(hogql_val_0)s), %(hogql_val_1)s) AS `$entry_current_url`, raw_sessions.session_id_v7 AS session_id_v7
@@ -225,7 +214,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT session_id, $entry_current_url
FROM sessions
WHERE and(equals(sessions.$entry_current_url, 'https://example.com/1'), 1)
@@ -244,7 +232,6 @@
# name: TestQuery.test_hogql_union_all_limits
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events
WHERE equals(events.team_id, 99999)
@@ -256,7 +243,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events
LIMIT 100 UNION ALL
@@ -268,7 +254,6 @@
# name: TestQuery.test_hogql_unnecessary_ifnull
'''
-- ClickHouse
-
SELECT toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS timestamp, JSONExtractInt(events.properties, %(hogql_val_1)s) AS json_int
FROM events
WHERE and(equals(events.team_id, 99999), greaterOrEquals(timestamp, addDays(today(), -10)), equals(json_int, 17))
@@ -276,7 +261,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT toDate(timestamp) AS timestamp, JSONExtractInt(properties, 'field') AS json_int
FROM events
WHERE and(greaterOrEquals(timestamp, addDays(today(), -10)), equals(json_int, 17))
@@ -286,7 +270,6 @@
# name: TestQuery.test_join_with_property_materialized_session_id
'''
-- ClickHouse
-
SELECT e.event AS event, s.session_id AS session_id
FROM events AS e LEFT JOIN (
SELECT session_replay_events.session_id AS session_id
@@ -298,7 +281,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT e.event, s.session_id
FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$session_id)
WHERE notEquals(e.properties.$session_id, NULL)
@@ -317,7 +299,6 @@
# name: TestQuery.test_join_with_property_not_materialized
'''
-- ClickHouse
-
SELECT e.event AS event, s.session_id AS session_id
FROM events AS e LEFT JOIN (
SELECT session_replay_events.session_id AS session_id
@@ -329,7 +310,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT e.event, s.session_id
FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$$$session_id)
WHERE notEquals(e.properties.$$$session_id, NULL)
@@ -348,7 +328,6 @@
# name: TestQuery.test_prop_cohort_basic
'''
-- ClickHouse
-
SELECT events.event AS event, count() AS `count()`
FROM events LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id
@@ -368,7 +347,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, count()
FROM events
WHERE in(person_id, (
@@ -384,7 +362,6 @@
# name: TestQuery.test_prop_cohort_basic.1
'''
-- ClickHouse
-
SELECT events.event AS event, count(*) AS `count(*)`
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -398,7 +375,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, count(*)
FROM events
WHERE in(person_id, (
@@ -414,7 +390,6 @@
# name: TestQuery.test_prop_cohort_static
'''
-- ClickHouse
-
SELECT events.event AS event, count() AS `count()`
FROM events LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id
@@ -432,7 +407,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, count()
FROM events
WHERE in(person_id, (
@@ -446,7 +420,6 @@
# name: TestQuery.test_prop_cohort_static.1
'''
-- ClickHouse
-
SELECT events.event AS event, count(*) AS `count(*)`
FROM events
WHERE and(equals(events.team_id, 99999), in(events.person_id, (
@@ -458,7 +431,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, count(*)
FROM events
WHERE in(person_id, (
@@ -472,7 +444,6 @@
# name: TestQuery.test_query
'''
-- ClickHouse
-
SELECT count() AS `count()`, events.event AS event
FROM events
WHERE and(equals(events.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), 0))
@@ -481,7 +452,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT count(), event
FROM events
WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')
@@ -492,7 +462,6 @@
# name: TestQuery.test_query_distinct
'''
-- ClickHouse
-
SELECT DISTINCT persons.properties___sneaky_mail AS sneaky_mail
FROM (
SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___sneaky_mail, tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___random_uuid, person.id AS id
@@ -508,7 +477,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT DISTINCT properties.sneaky_mail
FROM persons
WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')
@@ -518,7 +486,6 @@
# name: TestQuery.test_query_joins_events_e_pdi
'''
-- ClickHouse
-
SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_0)s) AS timestamp, e__pdi.distinct_id AS distinct_id, e__pdi.person_id AS person_id
FROM events AS e INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -532,7 +499,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, e.timestamp, e.pdi.distinct_id, pdi.person_id
FROM events AS e
LIMIT 10
@@ -541,7 +507,6 @@
# name: TestQuery.test_query_joins_events_first_to_persons
'''
-- ClickHouse
-
SELECT events.event AS event, persons.properties___email AS email
FROM events LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id
@@ -564,7 +529,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT events.event, persons.properties.email
FROM events JOIN persons ON equals(events.person_id, persons.id)
WHERE equals(events.event, 'pageview')
@@ -574,7 +538,6 @@
# name: TestQuery.test_query_joins_events_pdi
'''
-- ClickHouse
-
SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_0)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi.person_id AS person_id
FROM events INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -588,7 +551,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, pdi.distinct_id, pdi.person_id
FROM events
LIMIT 10
@@ -597,7 +559,6 @@
# name: TestQuery.test_query_joins_events_pdi_e_person_properties
'''
-- ClickHouse
-
SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, e__pdi.distinct_id AS distinct_id, e__pdi__person.properties___sneaky_mail AS sneaky_mail
FROM events AS e INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS e__pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -620,7 +581,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, e.timestamp, pdi.distinct_id, e.pdi.person.properties.sneaky_mail
FROM events AS e
LIMIT 10
@@ -629,7 +589,6 @@
# name: TestQuery.test_query_joins_events_pdi_person
'''
-- ClickHouse
-
SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_2)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi__person.id AS id
FROM events INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS events__pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -649,7 +608,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, pdi.distinct_id, pdi.person.id
FROM events
LIMIT 10
@@ -658,7 +616,6 @@
# name: TestQuery.test_query_joins_events_pdi_person_properties
'''
-- ClickHouse
-
SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_3)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi__person.properties___sneaky_mail AS sneaky_mail
FROM events INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS events__pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -681,7 +638,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, pdi.distinct_id, pdi.person.properties.sneaky_mail
FROM events
LIMIT 10
@@ -690,7 +646,6 @@
# name: TestQuery.test_query_joins_events_person_properties
'''
-- ClickHouse
-
SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, e__pdi__person.properties___sneaky_mail AS sneaky_mail
FROM events AS e INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS e__pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -713,7 +668,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, e.timestamp, e.pdi.person.properties.sneaky_mail
FROM events AS e
LIMIT 10
@@ -722,7 +676,6 @@
# name: TestQuery.test_query_joins_events_person_properties_in_aggregration
'''
-- ClickHouse
-
SELECT s__pdi__person.properties___sneaky_mail AS sneaky_mail, count() AS `count()`
FROM events AS s INNER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS s__pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -746,7 +699,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT s.pdi.person.properties.sneaky_mail, count()
FROM events AS s
GROUP BY s.pdi.person.properties.sneaky_mail
@@ -756,7 +708,6 @@
# name: TestQuery.test_query_joins_lazy_on_both_sides
'''
-- ClickHouse
-
SELECT e1.event, e2.event AS event
FROM events AS e1 LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id
@@ -779,7 +730,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT e1.event, e2.event
FROM events AS e1 JOIN events AS e2 ON equals(e1.person_id, e2.person_id)
WHERE and(equals(e1.event, 'pageview'), equals(e2.event, 'click'))
@@ -789,7 +739,6 @@
# name: TestQuery.test_query_joins_pdi
'''
-- ClickHouse
-
SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_0)s) AS timestamp, pdi.person_id AS person_id
FROM events AS e INNER JOIN (
SELECT person_distinct_id2.distinct_id AS distinct_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id
@@ -802,7 +751,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, pdi.person_id
FROM events AS e INNER JOIN (
SELECT distinct_id, argMax(person_id, version) AS person_id
@@ -815,7 +763,6 @@
# name: TestQuery.test_query_joins_pdi_person_properties
'''
-- ClickHouse
-
SELECT pdi.distinct_id AS distinct_id, pdi__person.properties___sneaky_mail AS sneaky_mail
FROM (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -837,7 +784,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT pdi.distinct_id, pdi.person.properties.sneaky_mail
FROM person_distinct_ids AS pdi
LIMIT 10
@@ -846,7 +792,6 @@
# name: TestQuery.test_query_joins_pdi_persons
'''
-- ClickHouse
-
SELECT pdi.distinct_id AS distinct_id, pdi__person.created_at AS created_at
FROM (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS pdi___person_id, tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -865,7 +810,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT pdi.distinct_id, pdi.person.created_at
FROM person_distinct_ids AS pdi
LIMIT 10
@@ -874,7 +818,6 @@
# name: TestQuery.test_query_joins_persons_to_events
'''
-- ClickHouse
-
SELECT persons.id AS id, events.event AS event
FROM (
SELECT person.id AS id
@@ -896,7 +839,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT persons.id, events.event
FROM persons JOIN events ON equals(persons.id, events.person_id)
LIMIT 10
@@ -905,7 +847,6 @@
# name: TestQuery.test_query_joins_simple
'''
-- ClickHouse
-
SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, pdi.distinct_id AS distinct_id, p.id AS id, p.properties___sneaky_mail AS sneaky_mail
FROM events AS e LEFT JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -928,7 +869,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, pdi.distinct_id, p.id, p.properties.sneaky_mail
FROM events AS e LEFT JOIN person_distinct_ids AS pdi ON equals(pdi.distinct_id, e.distinct_id) LEFT JOIN persons AS p ON equals(p.id, pdi.person_id)
LIMIT 100
@@ -937,7 +877,6 @@
# name: TestQuery.test_query_person_distinct_ids
'''
-- ClickHouse
-
SELECT DISTINCT person_distinct_ids.person_id AS person_id, person_distinct_ids.distinct_id AS distinct_id
FROM (
SELECT tupleElement(argMax(tuple(person_distinct_id2.person_id), person_distinct_id2.version), 1) AS person_id, person_distinct_id2.distinct_id AS distinct_id
@@ -950,7 +889,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT DISTINCT person_id, distinct_id
FROM person_distinct_ids
LIMIT 100
@@ -959,7 +897,6 @@
# name: TestQuery.test_query_select_person_with_joins_without_poe
'''
-- ClickHouse
-
SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_3)s) AS timestamp, events__person.id AS id, events__person.properties___sneaky_mail AS sneaky_mail
FROM events LEFT OUTER JOIN (
SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id
@@ -982,7 +919,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, person.id, person.properties.sneaky_mail
FROM events
LIMIT 10
@@ -991,7 +927,6 @@
# name: TestQuery.test_query_select_person_with_poe_without_joins
'''
-- ClickHouse
-
SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_0)s) AS timestamp, events.person_id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', '') AS sneaky_mail
FROM events
WHERE equals(events.team_id, 99999)
@@ -999,7 +934,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event, timestamp, person.id, person.properties.sneaky_mail
FROM events
LIMIT 10
@@ -1008,7 +942,6 @@
# name: TestQuery.test_select_person_on_events
'''
-- ClickHouse
-
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(s.person_properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS sneaky_mail, count() AS `count()`
FROM events AS s
WHERE equals(s.team_id, 99999)
@@ -1017,7 +950,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT poe.properties.sneaky_mail, count()
FROM events AS s
GROUP BY poe.properties.sneaky_mail
@@ -1027,7 +959,6 @@
# name: TestQuery.test_subquery
'''
-- ClickHouse
-
SELECT cnt AS cnt, event AS event
FROM (
SELECT count() AS cnt, events.event AS event
@@ -1039,7 +970,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT cnt, event
FROM (
SELECT count() AS cnt, event
@@ -1053,7 +983,6 @@
# name: TestQuery.test_subquery_alias
'''
-- ClickHouse
-
SELECT c.cnt AS cnt, c.event AS event
FROM (
SELECT count(*) AS cnt, events.event AS event
@@ -1065,7 +994,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT cnt, event
FROM (
SELECT count(*) AS cnt, event
@@ -1079,7 +1007,6 @@
# name: TestQuery.test_tuple_access
'''
-- ClickHouse
-
SELECT col_a AS col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r
FROM (
SELECT col_a AS col_a, groupArray(tuple(col_b, col_c)) AS g
@@ -1089,12 +1016,12 @@
WHERE equals(events.team_id, 99999)
GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), events.event)
GROUP BY col_a)
- GROUP BY col_a ORDER BY col_a ASC
+ GROUP BY col_a
+ ORDER BY col_a ASC
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r
FROM (
SELECT col_a, groupArray(tuple(col_b, col_c)) AS g
@@ -1103,7 +1030,8 @@
FROM events
GROUP BY properties.index, event)
GROUP BY col_a)
- GROUP BY col_a ORDER BY col_a ASC
+ GROUP BY col_a
+ ORDER BY col_a ASC
LIMIT 100
'''
# ---
@@ -1122,7 +1050,8 @@
FROM PIVOT_FUNCTION_1
GROUP BY PIVOT_FUNCTION_1.col_a)
SELECT PIVOT_FUNCTION_2.col_a AS col_a, PIVOT_FUNCTION_2.r AS r
- FROM PIVOT_FUNCTION_2 ORDER BY PIVOT_FUNCTION_2.col_a ASC
+ FROM PIVOT_FUNCTION_2
+ ORDER BY PIVOT_FUNCTION_2.col_a ASC
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
@@ -1138,7 +1067,8 @@
FROM PIVOT_FUNCTION_1
GROUP BY col_a)
SELECT col_a, r
- FROM PIVOT_FUNCTION_2 ORDER BY col_a ASC
+ FROM PIVOT_FUNCTION_2
+ ORDER BY col_a ASC
LIMIT 100
'''
# ---
@@ -1159,7 +1089,8 @@
SELECT PIVOT_FUNCTION_2.col_a AS col_a, PIVOT_FUNCTION_2.r AS r
FROM PIVOT_FUNCTION_2)
SELECT final.col_a AS col_a, final.r AS r
- FROM final ORDER BY final.col_a ASC
+ FROM final
+ ORDER BY final.col_a ASC
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
@@ -1177,7 +1108,8 @@
SELECT col_a, r
FROM PIVOT_FUNCTION_2)
SELECT col_a, r
- FROM final ORDER BY col_a ASC
+ FROM final
+ ORDER BY col_a ASC
LIMIT 100
'''
# ---
diff --git a/posthog/hogql/test/test_utils.py b/posthog/hogql/test/test_utils.py
index 0e099e4ce00a..cd24dd321b18 100644
--- a/posthog/hogql/test/test_utils.py
+++ b/posthog/hogql/test/test_utils.py
@@ -1,9 +1,11 @@
from posthog.test.base import BaseTest
+from unittest import TestCase
from parameterized import parameterized
from posthog.hogql import ast
from posthog.hogql.query import execute_hogql_query
+from posthog.hogql.test.utils import pretty_print_in_tests
from posthog.hogql.utils import deserialize_hx_ast, ilike_matches, like_matches
@@ -516,3 +518,66 @@ class TestUtils(BaseTest):
}
)
self.assertEqual(str(e.exception), "Invalid or missing '__hx_ast' kind: Invalid")
+
+
+class TestPrettyPrintInTests(TestCase):
+ @parameterized.expand(
+ [
+ (
+ "prewhere_stays_intact",
+ "SELECT 1 FROM events PREWHERE x WHERE y",
+ ["\nPREWHERE x", "\nWHERE y", "\nSELECT 1", "\nFROM events"],
+ ["PRE\nWHERE"],
+ ),
+ (
+ "all_top_level_keywords_split",
+ "SELECT a FROM t WHERE b GROUP BY c HAVING d QUALIFY q WINDOW w ORDER BY e LIMIT 1 OFFSET 2 SETTINGS x = 1",
+ [
+ "\nSELECT a",
+ "\nFROM t",
+ "\nWHERE b",
+ "\nGROUP BY",
+ "\nHAVING d",
+ "\nQUALIFY q",
+ "\nWINDOW w",
+ "\nORDER BY e",
+ "\nLIMIT 1",
+ "\nOFFSET 2",
+ "\nSETTINGS x = 1",
+ ],
+ ["PRE\nWHERE"],
+ ),
+ (
+ "keyword_substring_of_token_not_split",
+ "SELECT 1 FROM UNLIMITED",
+ ["\nFROM UNLIMITED"],
+ ["UN\nLIMITED", "\nLIMITED", "\nLIMIT"],
+ ),
+ (
+ "keyword_already_at_line_start_not_doubled",
+ "SELECT a\n FROM t\n WHERE b\n ORDER BY c",
+ ["\n FROM t", "\n WHERE b", "\n ORDER BY c"],
+ ["\n \nFROM", "\n \nWHERE", "\n \nORDER", "\n\nFROM"],
+ ),
+ (
+ "keyword_at_line_start_no_indent_not_doubled",
+ "SELECT a\nFROM t\nWHERE b",
+ ["SELECT a\nFROM t\nWHERE b"],
+ ["\n\nFROM", "\n\nWHERE"],
+ ),
+ ]
+ )
+ def test_keyword_newline_insertion(self, _name: str, query: str, present: list[str], absent: list[str]) -> None:
+ result = pretty_print_in_tests(query, 1)
+ for fragment in present:
+ self.assertIn(fragment, result)
+ for fragment in absent:
+ self.assertNotIn(fragment, result)
+
+ def test_normalizes_team_id(self) -> None:
+ result = pretty_print_in_tests("WHERE equals(events.team_id, 99999)", 99999)
+ self.assertIn("team_id, 420)", result)
+ self.assertNotIn("99999", result)
+
+ def test_none_query_returns_empty_string(self) -> None:
+ self.assertEqual(pretty_print_in_tests(None, 1), "")
diff --git a/posthog/hogql/test/utils.py b/posthog/hogql/test/utils.py
index 7dbe9f0daba8..37ee44bd43f0 100644
--- a/posthog/hogql/test/utils.py
+++ b/posthog/hogql/test/utils.py
@@ -22,16 +22,23 @@ def execute_hogql_query_with_timings(*args, **kwargs):
def pretty_print_in_tests(query: str | None, team_id: int) -> str:
if query is None:
return ""
- query = (
- query.replace("SELECT", "\nSELECT")
- .replace("FROM", "\nFROM")
- .replace("WHERE", "\nWHERE")
- .replace("GROUP", "\nGROUP")
- .replace("HAVING", "\nHAVING")
- .replace("LIMIT", "\nLIMIT")
- .replace("SETTINGS", "\nSETTINGS")
- .replace(f"team_id, {team_id})", "team_id, 420)")
+
+ # Newline before each top-level clause keyword for readable snapshots, but skip keywords already at the
+ # start of a (possibly indented) line so we don't stack a blank line on top of pretty-printed input. The \b
+ # boundaries keep keywords that are substrings of longer tokens intact (e.g. the WHERE inside PREWHERE).
+ def _newline_before_clause(match: "re.Match[str]") -> str:
+ start = match.start()
+ if start > 0 and match.string[start - 1] == "\n":
+ return match.group(0)
+ whitespace, keyword = match.group(1), match.group(2)
+ return f"{whitespace}\n{keyword}"
+
+ query = re.sub(
+ r"([ \t]*)\b(SELECT|FROM|PREWHERE|WHERE|GROUP|HAVING|QUALIFY|WINDOW|ORDER|LIMIT|OFFSET|SETTINGS)\b",
+ _newline_before_clause,
+ query,
)
+ query = query.replace(f"team_id, {team_id})", "team_id, 420)")
query = re.sub(r"in_cohort__[0-9]+", "in_cohort__XX", query)
query = re.sub(r"cohort_id, [0-9]+", "cohort_id, XX", query)
query = re.sub(r"RANDOM_TEST_ID::[a-f0-9\-]+", "RANDOM_TEST_ID::UUID", query)
diff --git a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr
index c7c3d1780b3d..4d91c886d1ff 100644
--- a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr
+++ b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr
@@ -2,7 +2,6 @@
# name: TestInCohort.test_in_cohort_conjoined_dynamic
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT cohortpeople.person_id AS cohort_person_id, 1 AS matched, cohortpeople.cohort_id AS cohort_id
@@ -13,7 +12,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id
@@ -26,7 +24,6 @@
# name: TestInCohort.test_in_cohort_conjoined_int
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id
@@ -37,7 +34,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id
@@ -50,7 +46,6 @@
# name: TestInCohort.test_in_cohort_conjoined_string
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id
@@ -61,7 +56,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id
@@ -74,7 +68,6 @@
# name: TestInCohort.test_in_cohort_deleted
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
@@ -85,7 +78,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
@@ -98,7 +90,6 @@
# name: TestInCohort.test_in_cohort_dynamic
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT cohortpeople.person_id AS person_id, 1 AS matched
@@ -111,7 +102,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
@@ -126,7 +116,6 @@
# name: TestInCohort.test_in_cohort_static
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
@@ -137,7 +126,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
@@ -150,7 +138,6 @@
# name: TestInCohort.test_in_cohort_strings
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
@@ -161,7 +148,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
@@ -174,7 +160,6 @@
# name: TestInlineCohortLeftjoin.test_inline_conjoined_mixed_static_and_dynamic
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id
@@ -192,14 +177,14 @@
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), 0), ifNull(less(tupleElement(argMax(tuple(toTimeZone(person.created_at, %(hogql_val_3)s)), person.version), 1), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))), 0))) AS persons
- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0) ORDER BY persons.id ASC
+ WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)
+ ORDER BY persons.id ASC
SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)
WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_6)s), ifNull(equals(__in_cohort.matched, 1), 0))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id
@@ -209,7 +194,8 @@
FROM ((
SELECT id
FROM persons
- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID') ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)
+ WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')
+ ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)
WHERE and(and(or(equals(1, 1), equals(1, 1)), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))
LIMIT 100
'''
@@ -217,7 +203,6 @@
# name: TestInlineCohortLeftjoin.test_inline_conjoined_off_vs_always
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT cohortpeople.person_id AS cohort_person_id, 1 AS matched, cohortpeople.cohort_id AS cohort_id
@@ -228,7 +213,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id
@@ -241,7 +225,6 @@
# name: TestInlineCohortLeftjoin.test_inline_conjoined_off_vs_always.1
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id
@@ -256,7 +239,8 @@
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), 0), ifNull(less(tupleElement(argMax(tuple(toTimeZone(person.created_at, %(hogql_val_3)s)), person.version), 1), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))), 0))) AS persons
- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0) ORDER BY persons.id ASC
+ WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)
+ ORDER BY persons.id ASC
SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto')) UNION ALL
SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id
FROM ((
@@ -270,26 +254,28 @@
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), %(hogql_val_8)s), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), 0), ifNull(less(tupleElement(argMax(tuple(toTimeZone(person.created_at, %(hogql_val_9)s)), person.version), 1), plus(now64(6, %(hogql_val_10)s), toIntervalDay(1))), 0))) AS persons
- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_11)s), 0) ORDER BY persons.id ASC
+ WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_11)s), 0)
+ ORDER BY persons.id ASC
SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)
WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_12)s), ifNull(equals(__in_cohort.matched, 1), 0))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id
FROM ((
SELECT id
FROM persons
- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID') ORDER BY id ASC)) UNION ALL
+ WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')
+ ORDER BY id ASC)) UNION ALL
SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id
FROM ((
SELECT id
FROM persons
- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID') ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)
+ WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')
+ ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)
WHERE and(and(or(equals(1, 1), equals(1, 1)), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))
LIMIT 100
'''
@@ -297,7 +283,6 @@
# name: TestInlineCohortLeftjoin.test_inline_leftjoin_off_vs_always
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT cohortpeople.person_id AS person_id, 1 AS matched
@@ -310,7 +295,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
@@ -325,7 +309,6 @@
# name: TestInlineCohortLeftjoin.test_inline_leftjoin_off_vs_always.1
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT id AS person_id, 1 AS matched
@@ -340,14 +323,14 @@
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), 0), ifNull(less(tupleElement(argMax(tuple(toTimeZone(person.created_at, %(hogql_val_3)s)), person.version), 1), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))), 0))) AS persons
- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0) ORDER BY persons.id ASC
+ WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)
+ ORDER BY persons.id ASC
SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)
WHERE and(equals(events.team_id, 99999), ifNull(equals(in_cohort__XX.matched, 1), 0), equals(events.event, %(hogql_val_6)s))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT id AS person_id, 1 AS matched
@@ -362,7 +345,8 @@
WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')))
GROUP BY raw_persons.id
HAVING and(equals(tupleElement(argMax(tuple(raw_persons.is_deleted), raw_persons.version), 1), 0), less(tupleElement(argMax(tuple(raw_persons.created_at), raw_persons.version), 1), plus(now(), toIntervalDay(1))))) AS persons
- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID') ORDER BY id ASC))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)
+ WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')
+ ORDER BY id ASC))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)
WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'))
LIMIT 100
'''
@@ -370,7 +354,6 @@
# name: TestInlineCohortLeftjoin.test_inline_static_always_uses_cohortpeople
'''
-- ClickHouse
-
SELECT events.event AS event
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
@@ -381,7 +364,6 @@
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT event
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
diff --git a/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr b/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr
index 43ed97b0f6a1..bb489bd30bf4 100644
--- a/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr
+++ b/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr
@@ -222,9 +222,11 @@
SELECT uniqState(events.distinct_id) AS unique_users, countState() AS total_events, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS host
FROM events
WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))
- GROUP BY host ORDER BY total_events DESC
+ GROUP BY host
+ ORDER BY total_events DESC
LIMIT 10)
- GROUP BY host ORDER BY total_events DESC
+ GROUP BY host
+ ORDER BY total_events DESC
LIMIT 10
'''
# ---
diff --git a/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr
index 116c445ffabd..5d9cfb23dda0 100644
--- a/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr
+++ b/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr
@@ -7,7 +7,8 @@
WHERE or(ilike(toString(properties.email), '%SEARCHSTRING%'), ilike(toString(properties.name), '%SEARCHSTRING%'), ilike(toString(id), '%SEARCHSTRING%'), in(id, (
SELECT person_id
FROM person_distinct_ids
- WHERE ilike(distinct_id, '%SEARCHSTRING%')))) ORDER BY id ASC
+ WHERE ilike(distinct_id, '%SEARCHSTRING%'))))
+ ORDER BY id ASC
LIMIT 50000
'''
# ---
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
index ea982d7b933a..748dddaf44d9 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr
@@ -8,7 +8,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -24,8 +23,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -50,8 +48,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -76,25 +73,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -107,7 +98,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -123,8 +113,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -149,8 +138,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -175,25 +163,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -206,7 +188,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -222,8 +203,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -248,8 +228,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -274,25 +253,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-20'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-20'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -305,7 +278,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -321,8 +293,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -347,8 +318,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -373,25 +343,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -404,7 +368,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -420,8 +383,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -446,8 +408,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -472,25 +433,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -503,7 +458,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -519,8 +473,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -545,8 +498,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -571,25 +523,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01')), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -602,7 +548,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -618,8 +563,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -644,8 +588,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -670,25 +613,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -701,7 +638,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_1
-
FROM
(
SELECT
@@ -717,8 +653,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -743,8 +678,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -769,25 +703,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(or(equals(event, 'sign_up'), equals(event, 'activate_account')), greaterOrEquals(events.timestamp, toDateTime('2023-06-01')), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-06-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -800,7 +728,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
coalesce(sum(conversion_value), 0) AS conversion_0
-
FROM
(
SELECT
@@ -816,8 +743,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
toFloat(conversion_math_value) AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -842,8 +768,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -868,25 +793,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -899,7 +818,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
coalesce(sum(conversion_value), 0) AS conversion_0
-
FROM
(
SELECT
@@ -915,8 +833,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
multiply(toFloat(conversion_math_value), attribution_weight) AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -940,8 +857,7 @@
filtered_utm_fbclids[tp_idx] AS fallback_fbclid,
filtered_utm_gad_sources[tp_idx] AS fallback_gad_source,
attribution_weights[tp_idx] AS attribution_weight
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -967,8 +883,7 @@
arrayMap(idx -> utm_fbclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_fbclids,
arrayMap(idx -> utm_gad_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gad_sources,
arrayMap(_x -> divide(1.0, greatest(toFloat(length(filtered_utm_timestamps)), 1.0)), filtered_utm_timestamps) AS attribution_weights
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -993,26 +908,20 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)
ARRAY JOIN arrayEnumerate(attribution_weights) AS tp_idx)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1025,7 +934,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
coalesce(sum(conversion_value), 0) AS conversion_0
-
FROM
(
SELECT
@@ -1041,8 +949,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
multiply(1, attribution_weight) AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1066,8 +973,7 @@
filtered_utm_fbclids[tp_idx] AS fallback_fbclid,
filtered_utm_gad_sources[tp_idx] AS fallback_gad_source,
attribution_weights[tp_idx] AS attribution_weight
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1093,8 +999,7 @@
arrayMap(idx -> utm_fbclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_fbclids,
arrayMap(idx -> utm_gad_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gad_sources,
arrayMap(_x -> divide(1.0, greatest(toFloat(length(filtered_utm_timestamps)), 1.0)), filtered_utm_timestamps) AS attribution_weights
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1119,26 +1024,20 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)
ARRAY JOIN arrayEnumerate(attribution_weights) AS tp_idx)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1151,7 +1050,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
coalesce(sum(conversion_value), 0) AS conversion_0
-
FROM
(
SELECT
@@ -1167,8 +1065,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
multiply(1, attribution_weight) AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1192,8 +1089,7 @@
filtered_utm_fbclids[tp_idx] AS fallback_fbclid,
filtered_utm_gad_sources[tp_idx] AS fallback_gad_source,
attribution_weights[tp_idx] AS attribution_weight
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1219,8 +1115,7 @@
arrayMap(idx -> utm_fbclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_fbclids,
arrayMap(idx -> utm_gad_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gad_sources,
if(equals(length(filtered_utm_timestamps), 0), [], if(equals(length(filtered_utm_timestamps), 1), [1.0], if(equals(length(filtered_utm_timestamps), 2), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(equals(ts, arrayMin(filtered_utm_timestamps)), 0.4, if(equals(ts, arrayMax(filtered_utm_timestamps)), 0.4, divide(0.2, greatest(minus(toFloat(length(filtered_utm_timestamps)), 2.0), 1.0)))), filtered_utm_timestamps))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(equals(ts, arrayMin(filtered_utm_timestamps)), 0.4, if(equals(ts, arrayMax(filtered_utm_timestamps)), 0.4, divide(0.2, greatest(minus(toFloat(length(filtered_utm_timestamps)), 2.0), 1.0)))), filtered_utm_timestamps)))))) AS attribution_weights
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1245,26 +1140,20 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)
ARRAY JOIN arrayEnumerate(attribution_weights) AS tp_idx)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1277,7 +1166,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
coalesce(sum(conversion_value), 0) AS conversion_0
-
FROM
(
SELECT
@@ -1293,8 +1181,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
multiply(1, attribution_weight) AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1318,8 +1205,7 @@
filtered_utm_fbclids[tp_idx] AS fallback_fbclid,
filtered_utm_gad_sources[tp_idx] AS fallback_gad_source,
attribution_weights[tp_idx] AS attribution_weight
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1345,8 +1231,7 @@
arrayMap(idx -> utm_fbclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_fbclids,
arrayMap(idx -> utm_gad_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gad_sources,
arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_timestamps[i], ts), 1944000))), filtered_utm_timestamps)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_timestamps[i], ts), 1944000))), filtered_utm_timestamps)) AS attribution_weights
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1371,26 +1256,20 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)
ARRAY JOIN arrayEnumerate(attribution_weights) AS tp_idx)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1403,7 +1282,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1419,8 +1297,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1445,8 +1322,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1471,25 +1347,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-04-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-04-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1502,7 +1372,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1518,8 +1387,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1544,8 +1412,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1570,25 +1437,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1601,7 +1462,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1617,8 +1477,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1643,8 +1502,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1669,25 +1527,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-12-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-12-01'), toIntervalSecond(31536000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1700,7 +1552,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1716,8 +1567,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1742,8 +1592,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1768,25 +1617,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1799,7 +1642,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1815,8 +1657,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1841,8 +1682,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1867,25 +1707,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
@@ -1898,7 +1732,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -1914,8 +1747,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -1940,8 +1772,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -1966,25 +1797,19 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 100
'''
# ---
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
index a9e0c4467166..4402c01afb29 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr
@@ -17,7 +17,6 @@
fromUnixTimestamp(conversion_time) AS conversion_timestamp,
fromUnixTimestamp(if(greater(last_utm_timestamp, 0), last_utm_timestamp, conversion_time)) AS touchpoint_timestamp,
1.0 AS touchpoint_weight
-
FROM
(
SELECT
@@ -43,8 +42,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -69,20 +67,15 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2025-01-01 00:00:00.000000')), lessOrEquals(events.timestamp, toDateTime('2025-01-02 00:00:00.000000'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-01-01 00:00:00.000000'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2025-01-02 00:00:00.000000'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)
-
LIMIT 50000
'''
# ---
@@ -95,7 +88,6 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
FROM
(
SELECT
@@ -111,18 +103,14 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2025-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2025-01-31 00:00:00.000000')))) AS attributed_conversions
-
GROUP BY
campaign,
id,
source
-
LIMIT 50000
'''
# ---
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr
index 7ac5977fc6cd..aec6347f355a 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr
@@ -8,7 +8,6 @@
conv.source AS source,
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['spring_sale_2024', 'spring-sale-2024'])), 'Spring Sale 2024', and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['holiday_campaign', 'holiday_promo'])), 'Holiday Promo', conv.campaign) AS match_key,
sum(conv.conversion_0) AS conversion_0
-
FROM
(
SELECT
@@ -16,8 +15,7 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -32,23 +30,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['spring_sale_2024', 'spring-sale-2024'])), 'Spring Sale 2024', and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['holiday_campaign', 'holiday_promo'])), 'Holiday Promo', conv.campaign),
conv.id,
conv.source
-
LIMIT 100
'''
# ---
@@ -61,7 +54,6 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
FROM
(
SELECT
@@ -69,8 +61,7 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -85,23 +76,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
conv.campaign,
conv.id,
conv.source
-
LIMIT 100
'''
# ---
@@ -114,7 +100,6 @@
conv.source AS source,
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['messy_campaign_1', 'messy_campaign_2', 'messy_campaign_3'])), 'Clean Campaign Name', conv.campaign) AS match_key,
sum(conv.conversion_0) AS conversion_0
-
FROM
(
SELECT
@@ -122,8 +107,7 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -138,23 +122,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['messy_campaign_1', 'messy_campaign_2', 'messy_campaign_3'])), 'Clean Campaign Name', conv.campaign),
conv.id,
conv.source
-
LIMIT 100
'''
# ---
@@ -167,7 +146,6 @@
conv.source AS source,
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['spring_sale_2024', 'spring-sale-2024', 'spring_sale'])), 'Spring Sale 2024', and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['bf_2024', 'blackfriday', 'bf-promo'])), 'Black Friday', and(in(lower(conv.source), ['meta', 'facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), in(lower(conv.campaign), ['spring_sale_fb', 'springsalefb'])), 'Spring Sale 2024', and(in(lower(conv.source), ['meta', 'facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), in(lower(conv.campaign), ['summer_2024', 'summer_promo'])), 'Summer Campaign', conv.campaign) AS match_key,
sum(conv.conversion_0) AS conversion_0
-
FROM
(
SELECT
@@ -175,8 +153,7 @@
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -191,23 +168,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
multiIf(and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['spring_sale_2024', 'spring-sale-2024', 'spring_sale'])), 'Spring Sale 2024', and(in(lower(conv.source), ['google', 'adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), in(lower(conv.campaign), ['bf_2024', 'blackfriday', 'bf-promo'])), 'Black Friday', and(in(lower(conv.source), ['meta', 'facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), in(lower(conv.campaign), ['spring_sale_fb', 'springsalefb'])), 'Spring Sale 2024', and(in(lower(conv.source), ['meta', 'facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), in(lower(conv.campaign), ['summer_2024', 'summer_promo'])), 'Summer Campaign', conv.campaign),
conv.id,
conv.source
-
LIMIT 100
'''
# ---
@@ -222,7 +194,6 @@
sum(conv.conversion_0) AS conversion_0,
sum(conv.conversion_1) AS conversion_1,
sum(conv.conversion_2) AS conversion_2
-
FROM
(
SELECT
@@ -232,8 +203,7 @@
count() AS conversion_0,
0 AS conversion_1,
0 AS conversion_2
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -248,28 +218,23 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source
UNION ALL
-
- SELECT
+ SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
0 AS conversion_0,
count() AS conversion_1,
0 AS conversion_2
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -284,28 +249,23 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000002')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source
UNION ALL
-
- SELECT
+ SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
0 AS conversion_0,
0 AS conversion_1,
count() AS conversion_2
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -320,23 +280,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000003')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
conv.campaign,
conv.id,
conv.source
-
LIMIT 100
'''
# ---
@@ -350,7 +305,6 @@
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0,
sum(conv.conversion_1) AS conversion_1
-
FROM
(
SELECT
@@ -359,8 +313,7 @@
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0,
0 AS conversion_1
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -375,27 +328,22 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000001')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source
UNION ALL
-
- SELECT
+ SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
0 AS conversion_0,
count() AS conversion_1
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -410,23 +358,18 @@
gad_source_name,
'-' AS campaign_id,
multiply(conversion_value, touchpoint_weight) AS conversion_value
-
- FROM
+ FROM
conversion_goal_attributed_preaggregated
-
- WHERE
+ WHERE
and(in(job_id, tuple('00000000-0000-0000-0000-000000000002')), equals(team_id, 420), greaterOrEquals(conversion_timestamp, toDateTime('2023-01-01 00:00:00.000000')), lessOrEquals(conversion_timestamp, toDateTime('2023-01-31 23:59:59.999999')))) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
GROUP BY
conv.campaign,
conv.id,
conv.source
-
LIMIT 100
'''
# ---
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner.ambr
index 34592e7c0160..d27a2854a0a6 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner.ambr
@@ -11,7 +11,6 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
FROM
(
SELECT
@@ -24,10 +23,8 @@
0.0 AS cost,
0.0 AS reported_conversion,
0.0 AS reported_conversion_value)
-
GROUP BY
multiIf(match(lower(nullIf(nullIf('', ''), 'null')), 'cross-network'), 'Cross Network', or(in(lower(nullIf(nullIf('cpc', ''), 'null')), tuple('cpc', 'cpm', 'cpv', 'cpa', 'ppc', 'retargeting')), startsWith(lower(nullIf(nullIf('cpc', ''), 'null')), 'paid'), false, notEquals(nullIf(nullIf(NULL, ''), 'null'), NULL)), coalesce(lookupPaidSourceType(lower(nullIf(nullIf(if(equals(lower(source), 'meta'), 'facebook', source), ''), 'null'))), if(match(lower(nullIf(nullIf('', ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Paid Shopping', NULL), lookupPaidMediumType(lower(nullIf(nullIf('cpc', ''), 'null'))), lookupPaidSourceType('$direct'), multiIf(equals(nullIf(nullIf(NULL, ''), 'null'), '1'), 'Paid Search', match(lower(nullIf(nullIf('', ''), 'null')), '^(.*video.*)$'), 'Paid Video', false, 'Paid Social', 'Paid Unknown')), and(equals('$direct', '$direct'), equals(lower(nullIf(nullIf('cpc', ''), 'null')), NULL), or(equals(lower(nullIf(nullIf(if(equals(lower(source), 'meta'), 'facebook', source), ''), 'null')), NULL), in(lower(nullIf(nullIf(if(equals(lower(source), 'meta'), 'facebook', source), ''), 'null')), tuple('(direct)', 'direct', '$direct'))), not(false)), 'Direct', coalesce(lookupOrganicSourceType(lower(nullIf(nullIf(if(equals(lower(source), 'meta'), 'facebook', source), ''), 'null'))), if(match(lower(nullIf(nullIf('', ''), 'null')), '^(.*(([^a-df-z]|^)shop|shopping).*)$'), 'Organic Shopping', NULL), lookupOrganicMediumType(lower(nullIf(nullIf('cpc', ''), 'null'))), lookupOrganicSourceType('$direct'), multiIf(match(lower(nullIf(nullIf('', ''), 'null')), '^(.*video.*)$'), 'Organic Video', match(lower(nullIf(nullIf('cpc', ''), 'null')), 'push$'), 'Push', false, 'Organic Social', equals('$direct', '$direct'), 'Direct', notEquals('$direct', NULL), 'Referral', 'Unknown')))
-
LIMIT 100
'''
# ---
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr
index 002a9cf76462..ac2d90b9d9b0 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr
@@ -13,8 +13,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -26,18 +25,14 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-11-30 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -51,12 +46,10 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
FROM
campaign_costs
ORDER BY
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -75,8 +68,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -88,14 +80,11 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source),
@@ -106,16 +95,14 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
- FROM
+ FROM
(
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -130,8 +117,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -156,8 +142,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -182,30 +167,23 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-01-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-01-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
- GROUP BY
+ GROUP BY
conv.campaign,
conv.id,
conv.source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -221,14 +199,12 @@
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`,
ucg.conversion_0 AS `Sign Up Conversions`,
round(divide(campaign_costs.total_cost, nullif(ucg.conversion_0, 0)), 2) AS `Cost per Sign Up Conversions`
-
FROM
campaign_costs
LEFT JOIN ucg ON and(equals(campaign_costs.match_key, ucg.match_key), equals(campaign_costs.source, ucg.source))
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -247,8 +223,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -260,18 +235,14 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -285,13 +256,11 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
FROM
campaign_costs
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -310,8 +279,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -323,18 +291,14 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -348,13 +312,11 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
FROM
campaign_costs
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -374,8 +336,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -387,15 +348,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign2) AS match_key,
toString(campaign2) AS campaign,
toString(campaign2) AS id,
@@ -405,15 +363,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend2), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_tiktok_ads_table` AS posthog_test_tiktok_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date2), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date2), toDateTime('2024-12-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign3) AS match_key,
toString(campaign3) AS campaign,
toString(campaign3) AS id,
@@ -423,18 +378,14 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend3), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_linkedin_ads_table` AS posthog_test_linkedin_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date3), toDateTime('2024-01-01 00:00:00')), lessOrEquals(toDateTime(date3), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -448,13 +399,11 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
FROM
campaign_costs
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
''',
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr
index c3f65dab0ff9..7ba9940783fd 100644
--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr
+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr
@@ -13,8 +13,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -26,18 +25,14 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-11-30 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
@@ -51,12 +46,10 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
FROM
campaign_costs
ORDER BY
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -79,7 +72,6 @@
tuple(current_period.`Cost per Reported Conversions`, previous_period.`Cost per Reported Conversions`) AS `Cost per Reported Conversions`,
tuple(current_period.`Sign Up Conversions`, previous_period.`Sign Up Conversions`) AS `Sign Up Conversions`,
tuple(current_period.`Cost per Sign Up Conversions`, previous_period.`Cost per Sign Up Conversions`) AS `Cost per Sign Up Conversions`
-
FROM
(WITH
campaign_costs AS (
@@ -93,8 +85,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -106,14 +97,11 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source),
@@ -124,16 +112,14 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
- FROM
+ FROM
(
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -148,8 +134,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -174,8 +159,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -200,31 +184,24 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
- GROUP BY
+ GROUP BY
conv.campaign,
conv.id,
conv.source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -239,8 +216,7 @@
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`,
ucg.conversion_0 AS `Sign Up Conversions`,
round(divide(campaign_costs.total_cost, nullif(ucg.conversion_0, 0)), 2) AS `Cost per Sign Up Conversions`
-
- FROM
+ FROM
campaign_costs
LEFT JOIN ucg ON and(equals(campaign_costs.match_key, ucg.match_key), equals(campaign_costs.source, ucg.source))) AS current_period
LEFT JOIN (WITH
@@ -255,8 +231,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -268,14 +243,11 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-09-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-10-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source),
@@ -286,16 +258,14 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
- FROM
+ FROM
(
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -310,8 +280,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -336,8 +305,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -362,31 +330,24 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
- GROUP BY
+ GROUP BY
conv.campaign,
conv.id,
conv.source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -401,14 +362,12 @@
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`,
ucg.conversion_0 AS `Sign Up Conversions`,
round(divide(campaign_costs.total_cost, nullif(ucg.conversion_0, 0)), 2) AS `Cost per Sign Up Conversions`
-
- FROM
+ FROM
campaign_costs
LEFT JOIN ucg ON and(equals(campaign_costs.match_key, ucg.match_key), equals(campaign_costs.source, ucg.source))) AS previous_period ON and(equals(current_period.Campaign, previous_period.Campaign), equals(current_period.Source, previous_period.Source))
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -431,7 +390,6 @@
tuple(current_period.`Cost per Reported Conversions`, previous_period.`Cost per Reported Conversions`) AS `Cost per Reported Conversions`,
tuple(current_period.`Sign Up Conversions`, previous_period.`Sign Up Conversions`) AS `Sign Up Conversions`,
tuple(current_period.`Cost per Sign Up Conversions`, previous_period.`Cost per Sign Up Conversions`) AS `Cost per Sign Up Conversions`
-
FROM
(WITH
campaign_costs AS (
@@ -445,8 +403,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -458,14 +415,11 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source),
@@ -476,16 +430,14 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
- FROM
+ FROM
(
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -500,8 +452,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -526,8 +477,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -552,31 +502,24 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
- GROUP BY
+ GROUP BY
conv.campaign,
conv.id,
conv.source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -591,8 +534,7 @@
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`,
ucg.conversion_0 AS `Sign Up Conversions`,
round(divide(campaign_costs.total_cost, nullif(ucg.conversion_0, 0)), 2) AS `Cost per Sign Up Conversions`
-
- FROM
+ FROM
campaign_costs
LEFT JOIN ucg ON and(equals(campaign_costs.match_key, ucg.match_key), equals(campaign_costs.source, ucg.source))) AS current_period
LEFT JOIN (WITH
@@ -607,8 +549,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -620,14 +561,11 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-09-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-10-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source),
@@ -638,16 +576,14 @@
conv.source AS source,
conv.campaign AS match_key,
sum(conv.conversion_0) AS conversion_0
-
- FROM
+ FROM
(
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,
count() AS conversion_0
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -662,8 +598,7 @@
if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name,
'-' AS campaign_id,
1 AS conversion_value
-
- FROM
+ FROM
(
SELECT
person_id,
@@ -688,8 +623,7 @@
if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid,
if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid,
if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_source
-
- FROM
+ FROM
(
SELECT
events.person_id,
@@ -714,31 +648,24 @@
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gclid, '')), ''))) AS utm_gclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$fbclid, '')), ''))) AS utm_fbclids,
arrayFilter(x -> notEmpty(x), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$gad_source, '')), ''))) AS utm_gad_sources
-
- FROM
+ FROM
events
-
- WHERE
+ WHERE
or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
events.person_id
-
- HAVING
+ HAVING
greater(length(conversion_timestamps), 0))
ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversions
-
- GROUP BY
+ GROUP BY
campaign,
id,
source) AS conv
-
- GROUP BY
+ GROUP BY
conv.campaign,
conv.id,
conv.source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -753,14 +680,12 @@
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`,
ucg.conversion_0 AS `Sign Up Conversions`,
round(divide(campaign_costs.total_cost, nullif(ucg.conversion_0, 0)), 2) AS `Cost per Sign Up Conversions`
-
- FROM
+ FROM
campaign_costs
LEFT JOIN ucg ON and(equals(campaign_costs.match_key, ucg.match_key), equals(campaign_costs.source, ucg.source))) AS previous_period ON and(equals(current_period.Campaign, previous_period.Campaign), equals(current_period.Source, previous_period.Source))
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
'''
@@ -782,7 +707,6 @@
tuple(current_period.`Reported Conversion Value`, previous_period.`Reported Conversion Value`) AS `Reported Conversion Value`,
tuple(current_period.`Reported ROAS`, previous_period.`Reported ROAS`) AS `Reported ROAS`,
tuple(current_period.`Cost per Reported Conversions`, previous_period.`Cost per Reported Conversions`) AS `Cost per Reported Conversions`
-
FROM
(WITH
campaign_costs AS (
@@ -796,8 +720,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -809,15 +732,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-12-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign2) AS match_key,
toString(campaign2) AS campaign,
toString(campaign2) AS id,
@@ -827,15 +747,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend2), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_tiktok_ads_table` AS posthog_test_tiktok_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date2), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date2), toDateTime('2024-12-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign3) AS match_key,
toString(campaign3) AS campaign,
toString(campaign3) AS id,
@@ -845,19 +762,15 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend3), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_linkedin_ads_table` AS posthog_test_linkedin_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date3), toDateTime('2024-11-01 00:00:00')), lessOrEquals(toDateTime(date3), toDateTime('2024-12-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -870,8 +783,7 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
- FROM
+ FROM
campaign_costs) AS current_period
LEFT JOIN (WITH
campaign_costs AS (
@@ -885,8 +797,7 @@
sum(ifNull(toFloat(impressions), 0)) AS total_impressions,
sum(ifNull(toFloat(reported_conversion), 0)) AS total_reported_conversions,
sum(ifNull(toFloat(reported_conversion_value), 0)) AS total_reported_conversion_value
-
- FROM
+ FROM
(
SELECT
toString(campaign1) AS match_key,
@@ -898,15 +809,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend1), 0))) AS cost,
toFloat(coalesce(toFloat(conversions1), 0)) AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_facebook_ads_table` AS posthog_test_facebook_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date1), toDateTime('2024-09-01 00:00:00')), lessOrEquals(toDateTime(date1), toDateTime('2024-10-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign2) AS match_key,
toString(campaign2) AS campaign,
toString(campaign2) AS id,
@@ -916,15 +824,12 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend2), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_tiktok_ads_table` AS posthog_test_tiktok_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date2), toDateTime('2024-09-01 00:00:00')), lessOrEquals(toDateTime(date2), toDateTime('2024-10-31 23:59:59')))
UNION ALL
-
- SELECT
+ SELECT
toString(campaign3) AS match_key,
toString(campaign3) AS campaign,
toString(campaign3) AS id,
@@ -934,19 +839,15 @@
toFloat(convertCurrency('USD', 'USD', coalesce(toFloat(spend3), 0))) AS cost,
0 AS reported_conversion,
0 AS reported_conversion_value
-
- FROM
+ FROM
`bigquery.posthog_test.posthog_test_linkedin_ads_table` AS posthog_test_linkedin_ads_table
-
- WHERE
+ WHERE
and(greaterOrEquals(toDateTime(date3), toDateTime('2024-09-01 00:00:00')), lessOrEquals(toDateTime(date3), toDateTime('2024-10-31 23:59:59'))))
-
- GROUP BY
+ GROUP BY
campaign,
id,
source)
-
- SELECT
+ SELECT
campaign_costs.id AS ID,
campaign_costs.campaign AS Campaign,
campaign_costs.source AS Source,
@@ -959,13 +860,11 @@
round(campaign_costs.total_reported_conversion_value, 2) AS `Reported Conversion Value`,
round(divide(campaign_costs.total_reported_conversion_value, nullif(campaign_costs.total_cost, 0)), 2) AS `Reported ROAS`,
round(divide(campaign_costs.total_cost, nullif(campaign_costs.total_reported_conversions, 0)), 2) AS `Cost per Reported Conversions`
-
- FROM
+ FROM
campaign_costs) AS previous_period ON and(equals(current_period.Campaign, previous_period.Campaign), equals(current_period.Source, previous_period.Source))
ORDER BY
Cost DESC,
ID ASC
-
LIMIT 101
OFFSET 0
''',
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
index c53ca258cd8b..e9465cb0cf52 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
@@ -2,246 +2,188 @@
# name: TestTrafficTypeSnapshot.test_filter_bots_sql_query
'''
-- ClickHouse
-
SELECT
events.event AS event,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS user_agent
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_1)s), not(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), %(hogql_val_3)s), [%(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s]), 0), 1)))
ORDER BY
user_agent ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
event,
properties.$user_agent AS user_agent
-
FROM
events
-
WHERE
and(equals(event, '$pageview'), not(notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0)))
ORDER BY
user_agent ASC
-
LIMIT 100
'''
# ---
# name: TestTrafficTypeSnapshot.test_get_bot_name
'''
-- ClickHouse
-
SELECT
if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s]), 0), 0), %(hogql_val_110)s, [%(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s, %(hogql_val_203)s, %(hogql_val_204)s, %(hogql_val_205)s, %(hogql_val_206)s, %(hogql_val_207)s, %(hogql_val_208)s, %(hogql_val_209)s, %(hogql_val_210)s, %(hogql_val_211)s, %(hogql_val_212)s, %(hogql_val_213)s, %(hogql_val_214)s, %(hogql_val_215)s, %(hogql_val_216)s, %(hogql_val_217)s, %(hogql_val_218)s][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_219)s), ''), 'null'), '^"|"$', ''), %(hogql_val_220)s), [%(hogql_val_221)s, %(hogql_val_222)s, %(hogql_val_223)s, %(hogql_val_224)s, %(hogql_val_225)s, %(hogql_val_226)s, %(hogql_val_227)s, %(hogql_val_228)s, %(hogql_val_229)s, %(hogql_val_230)s, %(hogql_val_231)s, %(hogql_val_232)s, %(hogql_val_233)s, %(hogql_val_234)s, %(hogql_val_235)s, %(hogql_val_236)s, %(hogql_val_237)s, %(hogql_val_238)s, %(hogql_val_239)s, %(hogql_val_240)s, %(hogql_val_241)s, %(hogql_val_242)s, %(hogql_val_243)s, %(hogql_val_244)s, %(hogql_val_245)s, %(hogql_val_246)s, %(hogql_val_247)s, %(hogql_val_248)s, %(hogql_val_249)s, %(hogql_val_250)s, %(hogql_val_251)s, %(hogql_val_252)s, %(hogql_val_253)s, %(hogql_val_254)s, %(hogql_val_255)s, %(hogql_val_256)s, %(hogql_val_257)s, %(hogql_val_258)s, %(hogql_val_259)s, %(hogql_val_260)s, %(hogql_val_261)s, %(hogql_val_262)s, %(hogql_val_263)s, %(hogql_val_264)s, %(hogql_val_265)s, %(hogql_val_266)s, %(hogql_val_267)s, %(hogql_val_268)s, %(hogql_val_269)s, %(hogql_val_270)s, %(hogql_val_271)s, %(hogql_val_272)s, %(hogql_val_273)s, %(hogql_val_274)s, %(hogql_val_275)s, %(hogql_val_276)s, %(hogql_val_277)s, %(hogql_val_278)s, %(hogql_val_279)s, %(hogql_val_280)s, %(hogql_val_281)s, %(hogql_val_282)s, %(hogql_val_283)s, %(hogql_val_284)s, %(hogql_val_285)s, %(hogql_val_286)s, %(hogql_val_287)s, %(hogql_val_288)s, %(hogql_val_289)s, %(hogql_val_290)s, %(hogql_val_291)s, %(hogql_val_292)s, %(hogql_val_293)s, %(hogql_val_294)s, %(hogql_val_295)s, %(hogql_val_296)s, %(hogql_val_297)s, %(hogql_val_298)s, %(hogql_val_299)s, %(hogql_val_300)s, %(hogql_val_301)s, %(hogql_val_302)s, %(hogql_val_303)s, %(hogql_val_304)s, %(hogql_val_305)s, %(hogql_val_306)s, %(hogql_val_307)s, %(hogql_val_308)s, %(hogql_val_309)s, %(hogql_val_310)s, %(hogql_val_311)s, %(hogql_val_312)s, %(hogql_val_313)s, %(hogql_val_314)s, %(hogql_val_315)s, %(hogql_val_316)s, %(hogql_val_317)s, %(hogql_val_318)s, %(hogql_val_319)s, %(hogql_val_320)s, %(hogql_val_321)s, %(hogql_val_322)s, %(hogql_val_323)s, %(hogql_val_324)s, %(hogql_val_325)s, %(hogql_val_326)s, %(hogql_val_327)s, %(hogql_val_328)s])]) AS bot_name,
count() AS count
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_329)s))
-
GROUP BY
bot_name
ORDER BY
bot_name ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
if(equals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0), '', ['GPTBot', 'Google Cloud Vertex', 'Google AI', 'GoogleOther', 'Claude Search', 'Claude User', 'Claude', 'Claude Web', 'Anthropic', 'Perplexity User', 'Perplexity', 'Common Crawl', 'Meta AI', 'ByteDance', 'TikTok AI', 'Cohere', 'Diffbot', 'Webz.io', 'Webz.io Extended', 'Timpi', 'Amazon', 'Petal', 'Brightbot', 'OpenAI Search', 'Apple AI', 'ChatGPT', 'Meta Fetcher', 'Meta Fetcher', 'DuckDuckGo AI', 'Mistral AI', 'Manus', 'NotebookLM', 'Shap', 'PostHog Code Desktop', 'PostHog Code Mobile', 'PostHog Code Agent', 'PostHog Code Cloud', 'Applebot', 'Googlebot', 'Bingbot', 'Bingbot', 'Yandex', 'Baidu', 'DuckDuckGo', 'Yahoo', 'Naver', 'Yisou', 'Sogou', 'Pageburst', '360 Spider', 'Google Ads', 'Google Inspection', 'Google Food', 'Ahrefs Site Audit', 'Ahrefs', 'Barkrowler', 'Semrush', 'SE Ranking', 'Majestic', 'Moz', 'Lighthouse', 'Meltwater', 'Facebook Bot', 'Facebook', 'Twitter', 'LinkedIn', 'Pinterest', 'Slack', 'Slack Image Proxy', 'Telegram', 'WhatsApp', 'Google Image Proxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'Grafana Synthetic', 'Doctom Monitor', 'DigitalOcean Uptime', 'curl', 'Wget', 'Python Requests', 'Axios', 'Node Fetch', 'Go HTTP', 'OkHttp', 'Apache HTTP', 'LWP', 'Scrapy', 'Google Play Store', 'Amazon CloudFront', 'Amazon Product Discovery', 'Google Business Link', 'Google Storebot', 'Google Read Aloud', 'Google Appointments', 'Google Actions', 'OneTrust', 'Chrome Prefetch Proxy', 'Mozlila Typo Bot', 'Headless Chrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', ''][multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$'])]) AS bot_name,
count() AS count
-
FROM
events
-
WHERE
equals(event, '$pageview')
-
GROUP BY
bot_name
ORDER BY
bot_name ASC
-
LIMIT 100
'''
# ---
# name: TestTrafficTypeSnapshot.test_get_bot_type
'''
-- ClickHouse
-
SELECT
if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s]), 0), 0), %(hogql_val_110)s, [%(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s, %(hogql_val_203)s, %(hogql_val_204)s, %(hogql_val_205)s, %(hogql_val_206)s, %(hogql_val_207)s, %(hogql_val_208)s, %(hogql_val_209)s, %(hogql_val_210)s, %(hogql_val_211)s, %(hogql_val_212)s, %(hogql_val_213)s, %(hogql_val_214)s, %(hogql_val_215)s, %(hogql_val_216)s, %(hogql_val_217)s, %(hogql_val_218)s][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_219)s), ''), 'null'), '^"|"$', ''), %(hogql_val_220)s), [%(hogql_val_221)s, %(hogql_val_222)s, %(hogql_val_223)s, %(hogql_val_224)s, %(hogql_val_225)s, %(hogql_val_226)s, %(hogql_val_227)s, %(hogql_val_228)s, %(hogql_val_229)s, %(hogql_val_230)s, %(hogql_val_231)s, %(hogql_val_232)s, %(hogql_val_233)s, %(hogql_val_234)s, %(hogql_val_235)s, %(hogql_val_236)s, %(hogql_val_237)s, %(hogql_val_238)s, %(hogql_val_239)s, %(hogql_val_240)s, %(hogql_val_241)s, %(hogql_val_242)s, %(hogql_val_243)s, %(hogql_val_244)s, %(hogql_val_245)s, %(hogql_val_246)s, %(hogql_val_247)s, %(hogql_val_248)s, %(hogql_val_249)s, %(hogql_val_250)s, %(hogql_val_251)s, %(hogql_val_252)s, %(hogql_val_253)s, %(hogql_val_254)s, %(hogql_val_255)s, %(hogql_val_256)s, %(hogql_val_257)s, %(hogql_val_258)s, %(hogql_val_259)s, %(hogql_val_260)s, %(hogql_val_261)s, %(hogql_val_262)s, %(hogql_val_263)s, %(hogql_val_264)s, %(hogql_val_265)s, %(hogql_val_266)s, %(hogql_val_267)s, %(hogql_val_268)s, %(hogql_val_269)s, %(hogql_val_270)s, %(hogql_val_271)s, %(hogql_val_272)s, %(hogql_val_273)s, %(hogql_val_274)s, %(hogql_val_275)s, %(hogql_val_276)s, %(hogql_val_277)s, %(hogql_val_278)s, %(hogql_val_279)s, %(hogql_val_280)s, %(hogql_val_281)s, %(hogql_val_282)s, %(hogql_val_283)s, %(hogql_val_284)s, %(hogql_val_285)s, %(hogql_val_286)s, %(hogql_val_287)s, %(hogql_val_288)s, %(hogql_val_289)s, %(hogql_val_290)s, %(hogql_val_291)s, %(hogql_val_292)s, %(hogql_val_293)s, %(hogql_val_294)s, %(hogql_val_295)s, %(hogql_val_296)s, %(hogql_val_297)s, %(hogql_val_298)s, %(hogql_val_299)s, %(hogql_val_300)s, %(hogql_val_301)s, %(hogql_val_302)s, %(hogql_val_303)s, %(hogql_val_304)s, %(hogql_val_305)s, %(hogql_val_306)s, %(hogql_val_307)s, %(hogql_val_308)s, %(hogql_val_309)s, %(hogql_val_310)s, %(hogql_val_311)s, %(hogql_val_312)s, %(hogql_val_313)s, %(hogql_val_314)s, %(hogql_val_315)s, %(hogql_val_316)s, %(hogql_val_317)s, %(hogql_val_318)s, %(hogql_val_319)s, %(hogql_val_320)s, %(hogql_val_321)s, %(hogql_val_322)s, %(hogql_val_323)s, %(hogql_val_324)s, %(hogql_val_325)s, %(hogql_val_326)s, %(hogql_val_327)s, %(hogql_val_328)s])]) AS bot_type,
count() AS count
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_329)s))
-
GROUP BY
bot_type
ORDER BY
bot_type ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
if(equals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0), '', ['ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_search', 'ai_assistant', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_search', 'ai_search', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_search', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'no_user_agent'][multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$'])]) AS bot_type,
count() AS count
-
FROM
events
-
WHERE
equals(event, '$pageview')
-
GROUP BY
bot_type
ORDER BY
bot_type ASC
-
LIMIT 100
'''
# ---
# name: TestTrafficTypeSnapshot.test_get_traffic_category
'''
-- ClickHouse
-
SELECT
if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s]), 0), 0), %(hogql_val_110)s, [%(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s, %(hogql_val_203)s, %(hogql_val_204)s, %(hogql_val_205)s, %(hogql_val_206)s, %(hogql_val_207)s, %(hogql_val_208)s, %(hogql_val_209)s, %(hogql_val_210)s, %(hogql_val_211)s, %(hogql_val_212)s, %(hogql_val_213)s, %(hogql_val_214)s, %(hogql_val_215)s, %(hogql_val_216)s, %(hogql_val_217)s, %(hogql_val_218)s][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_219)s), ''), 'null'), '^"|"$', ''), %(hogql_val_220)s), [%(hogql_val_221)s, %(hogql_val_222)s, %(hogql_val_223)s, %(hogql_val_224)s, %(hogql_val_225)s, %(hogql_val_226)s, %(hogql_val_227)s, %(hogql_val_228)s, %(hogql_val_229)s, %(hogql_val_230)s, %(hogql_val_231)s, %(hogql_val_232)s, %(hogql_val_233)s, %(hogql_val_234)s, %(hogql_val_235)s, %(hogql_val_236)s, %(hogql_val_237)s, %(hogql_val_238)s, %(hogql_val_239)s, %(hogql_val_240)s, %(hogql_val_241)s, %(hogql_val_242)s, %(hogql_val_243)s, %(hogql_val_244)s, %(hogql_val_245)s, %(hogql_val_246)s, %(hogql_val_247)s, %(hogql_val_248)s, %(hogql_val_249)s, %(hogql_val_250)s, %(hogql_val_251)s, %(hogql_val_252)s, %(hogql_val_253)s, %(hogql_val_254)s, %(hogql_val_255)s, %(hogql_val_256)s, %(hogql_val_257)s, %(hogql_val_258)s, %(hogql_val_259)s, %(hogql_val_260)s, %(hogql_val_261)s, %(hogql_val_262)s, %(hogql_val_263)s, %(hogql_val_264)s, %(hogql_val_265)s, %(hogql_val_266)s, %(hogql_val_267)s, %(hogql_val_268)s, %(hogql_val_269)s, %(hogql_val_270)s, %(hogql_val_271)s, %(hogql_val_272)s, %(hogql_val_273)s, %(hogql_val_274)s, %(hogql_val_275)s, %(hogql_val_276)s, %(hogql_val_277)s, %(hogql_val_278)s, %(hogql_val_279)s, %(hogql_val_280)s, %(hogql_val_281)s, %(hogql_val_282)s, %(hogql_val_283)s, %(hogql_val_284)s, %(hogql_val_285)s, %(hogql_val_286)s, %(hogql_val_287)s, %(hogql_val_288)s, %(hogql_val_289)s, %(hogql_val_290)s, %(hogql_val_291)s, %(hogql_val_292)s, %(hogql_val_293)s, %(hogql_val_294)s, %(hogql_val_295)s, %(hogql_val_296)s, %(hogql_val_297)s, %(hogql_val_298)s, %(hogql_val_299)s, %(hogql_val_300)s, %(hogql_val_301)s, %(hogql_val_302)s, %(hogql_val_303)s, %(hogql_val_304)s, %(hogql_val_305)s, %(hogql_val_306)s, %(hogql_val_307)s, %(hogql_val_308)s, %(hogql_val_309)s, %(hogql_val_310)s, %(hogql_val_311)s, %(hogql_val_312)s, %(hogql_val_313)s, %(hogql_val_314)s, %(hogql_val_315)s, %(hogql_val_316)s, %(hogql_val_317)s, %(hogql_val_318)s, %(hogql_val_319)s, %(hogql_val_320)s, %(hogql_val_321)s, %(hogql_val_322)s, %(hogql_val_323)s, %(hogql_val_324)s, %(hogql_val_325)s, %(hogql_val_326)s, %(hogql_val_327)s, %(hogql_val_328)s])]) AS category,
count() AS count
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_329)s))
-
GROUP BY
category
ORDER BY
category ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
if(equals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0), 'regular', ['ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_search', 'ai_assistant', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_crawler', 'ai_search', 'ai_search', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_assistant', 'ai_search', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'search_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'seo_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'social_crawler', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'monitoring', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'http_client', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'headless_browser', 'no_user_agent'][multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$'])]) AS category,
count() AS count
-
FROM
events
-
WHERE
equals(event, '$pageview')
-
GROUP BY
category
ORDER BY
category ASC
-
LIMIT 100
'''
# ---
# name: TestTrafficTypeSnapshot.test_get_traffic_type
'''
-- ClickHouse
-
SELECT
if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s]), 0), 0), %(hogql_val_110)s, [%(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s, %(hogql_val_203)s, %(hogql_val_204)s, %(hogql_val_205)s, %(hogql_val_206)s, %(hogql_val_207)s, %(hogql_val_208)s, %(hogql_val_209)s, %(hogql_val_210)s, %(hogql_val_211)s, %(hogql_val_212)s, %(hogql_val_213)s, %(hogql_val_214)s, %(hogql_val_215)s, %(hogql_val_216)s, %(hogql_val_217)s, %(hogql_val_218)s][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_219)s), ''), 'null'), '^"|"$', ''), %(hogql_val_220)s), [%(hogql_val_221)s, %(hogql_val_222)s, %(hogql_val_223)s, %(hogql_val_224)s, %(hogql_val_225)s, %(hogql_val_226)s, %(hogql_val_227)s, %(hogql_val_228)s, %(hogql_val_229)s, %(hogql_val_230)s, %(hogql_val_231)s, %(hogql_val_232)s, %(hogql_val_233)s, %(hogql_val_234)s, %(hogql_val_235)s, %(hogql_val_236)s, %(hogql_val_237)s, %(hogql_val_238)s, %(hogql_val_239)s, %(hogql_val_240)s, %(hogql_val_241)s, %(hogql_val_242)s, %(hogql_val_243)s, %(hogql_val_244)s, %(hogql_val_245)s, %(hogql_val_246)s, %(hogql_val_247)s, %(hogql_val_248)s, %(hogql_val_249)s, %(hogql_val_250)s, %(hogql_val_251)s, %(hogql_val_252)s, %(hogql_val_253)s, %(hogql_val_254)s, %(hogql_val_255)s, %(hogql_val_256)s, %(hogql_val_257)s, %(hogql_val_258)s, %(hogql_val_259)s, %(hogql_val_260)s, %(hogql_val_261)s, %(hogql_val_262)s, %(hogql_val_263)s, %(hogql_val_264)s, %(hogql_val_265)s, %(hogql_val_266)s, %(hogql_val_267)s, %(hogql_val_268)s, %(hogql_val_269)s, %(hogql_val_270)s, %(hogql_val_271)s, %(hogql_val_272)s, %(hogql_val_273)s, %(hogql_val_274)s, %(hogql_val_275)s, %(hogql_val_276)s, %(hogql_val_277)s, %(hogql_val_278)s, %(hogql_val_279)s, %(hogql_val_280)s, %(hogql_val_281)s, %(hogql_val_282)s, %(hogql_val_283)s, %(hogql_val_284)s, %(hogql_val_285)s, %(hogql_val_286)s, %(hogql_val_287)s, %(hogql_val_288)s, %(hogql_val_289)s, %(hogql_val_290)s, %(hogql_val_291)s, %(hogql_val_292)s, %(hogql_val_293)s, %(hogql_val_294)s, %(hogql_val_295)s, %(hogql_val_296)s, %(hogql_val_297)s, %(hogql_val_298)s, %(hogql_val_299)s, %(hogql_val_300)s, %(hogql_val_301)s, %(hogql_val_302)s, %(hogql_val_303)s, %(hogql_val_304)s, %(hogql_val_305)s, %(hogql_val_306)s, %(hogql_val_307)s, %(hogql_val_308)s, %(hogql_val_309)s, %(hogql_val_310)s, %(hogql_val_311)s, %(hogql_val_312)s, %(hogql_val_313)s, %(hogql_val_314)s, %(hogql_val_315)s, %(hogql_val_316)s, %(hogql_val_317)s, %(hogql_val_318)s, %(hogql_val_319)s, %(hogql_val_320)s, %(hogql_val_321)s, %(hogql_val_322)s, %(hogql_val_323)s, %(hogql_val_324)s, %(hogql_val_325)s, %(hogql_val_326)s, %(hogql_val_327)s, %(hogql_val_328)s])]) AS traffic_type,
count() AS count
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_329)s))
-
GROUP BY
traffic_type
ORDER BY
traffic_type ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
if(equals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0), 'Regular', ['AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'AI Agent', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation', 'Automation'][multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$'])]) AS traffic_type,
count() AS count
-
FROM
events
-
WHERE
equals(event, '$pageview')
-
GROUP BY
traffic_type
ORDER BY
traffic_type ASC
-
LIMIT 100
'''
# ---
# name: TestTrafficTypeSnapshot.test_is_bot
'''
-- ClickHouse
-
SELECT
ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s]), 0), 1) AS is_bot,
count() AS count
-
FROM
events
-
WHERE
and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_110)s))
-
GROUP BY
is_bot
ORDER BY
is_bot ASC
-
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0
-- HogQL
-
SELECT
notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0) AS is_bot,
count() AS count
-
FROM
events
-
WHERE
equals(event, '$pageview')
-
GROUP BY
is_bot
ORDER BY
is_bot ASC
-
LIMIT 100
'''
# ---