: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(insights): move paths query runner to product_analytics product (#58954)
Thomas Obermüllerd0c4d9deff4f
diff --git a/posthog/hogql_queries/insights/insight_actors_query_runner.py b/posthog/hogql_queries/insights/insight_actors_query_runner.pyindex 5a70b3added0..f948b082253d 100644--- a/posthog/hogql_queries/insights/insight_actors_query_runner.py+++ b/posthog/hogql_queries/insights/insight_actors_query_runner.py@@ -26,7 +26,6 @@ from posthog.hogql_queries.experiments.experiment_query_runner import Experimentfrom posthog.hogql_queries.insights.funnels.funnel_correlation_query_runner import FunnelCorrelationQueryRunnerfrom posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.lifecycle.lifecycle_query_runner import LifecycleQueryRunner-from posthog.hogql_queries.insights.paths.paths_query_runner import PathsQueryRunnerfrom posthog.hogql_queries.insights.retention.retention_query_runner import RetentionQueryRunnerfrom posthog.hogql_queries.insights.stickiness.stickiness_query_runner import StickinessQueryRunnerfrom posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner@@ -35,6 +34,8 @@ from posthog.models import Teamfrom posthog.models.filters.mixins.utils import cached_propertyfrom posthog.types import InsightActorsQueryNode+from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner+class InsightActorsQueryRunner(AnalyticsQueryRunner[HogQLQueryResponse]):query: InsightActorsQueryNodediff --git a/posthog/hogql_queries/insights/paths/test/__snapshots__/test_paths_query_runner_ee.ambr b/posthog/hogql_queries/insights/paths/test/__snapshots__/test_paths_query_runner_ee.ambrdeleted file mode 100644index af192b7884ce..000000000000--- a/posthog/hogql_queries/insights/paths/test/__snapshots__/test_paths_query_runner_ee.ambr+++ /dev/null@@ -1,16953 +0,0 @@-# serializer version: 1-# name: ClickhousePathsUDF.test_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_end.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_end_materialized.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_exclusion_filters_with_wildcard_groups- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_exclusion_filters_with_wildcard_groups.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/xxx/invalid/*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/xxx/invalid/.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_inclusion_exclusion_filters- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_inclusion_exclusion_filters.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$screen'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_inclusion_exclusion_filters.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_inclusion_exclusion_filters.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))), notIn(path_item, ['/custom1', '/1', '/2', '/3'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_event_ordering- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-03 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_groups_filtering_person_on_events- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'finance'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_groups_filtering_person_on_events.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'technology'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_groups_filtering_person_on_events.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 1))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_1 ON equals(events.`$group_1`, events__group_1.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_1.properties___industry, 'technology'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_step two'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_step three'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.5- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '4_step four'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_dropoffs.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_person_on_events_v2- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'poev2_p2'- '''-# ----# name: ClickhousePathsUDF.test_person_on_events_v2.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_recording- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_recording.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s3', 's1', 's5']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 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- '''-# ----# name: ClickhousePathsUDF.test_recording_for_dropoff- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_recording_for_dropoff.1- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_recording_for_dropoff.2- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: ClickhousePathsUDF.test_recording_with_no_window_or_session_id- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_recording_with_no_window_or_session_id.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: ClickhousePathsUDF.test_recording_with_start_and_end- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/3') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/1') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/3') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, '/3') AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, indexOf(compact_path, '/1') AS start_target_index, if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path, indexOf(start_filtered_path, '/3') AS end_target_index, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path, if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path, if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings, if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings, if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid, if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid, if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp, if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp, if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id, if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id, if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id, if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_recording_with_start_and_end.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: ClickhousePathsUDF.test_respect_session_limits- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_start_and_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_start_and_end.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_start_and_end.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_start_and_end.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_start_and_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_start_and_end_materialized.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_start_and_end_materialized.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_start_and_end_materialized.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_start_dropping_orphaned_edges- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/2') AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_step_conversion_times- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_step_limit- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_step_limit.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_step_limit.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_step_limit.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_step_limit.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 3) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 3) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 3) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 3) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_step_limit.5- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_step_limit.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_step_limit.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_step_limit.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '3_/3'), 0), ifNull(equals(path_key, '4_/4'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: ClickhousePathsUDF.test_wildcard_groups_across_people- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: ClickhousePathsUDF.test_wildcard_groups_evil_input- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['(a+)+',- '[aaa|aaaa]+',- '1.*',- '.*',- '/3?q=1',- '/3*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['\\(a\\+\\)\\+', '\\[aaa\\|aaaa\\]\\+', '1\\..*', '\\..*', '/3\\?q=1', '/3.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_end.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_end_materialized.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_exclusion_filters_with_wildcard_groups- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_exclusion_filters_with_wildcard_groups.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/xxx/invalid/*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/xxx/invalid/.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_inclusion_exclusion_filters- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$screen'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))), notIn(path_item, ['/custom1', '/1', '/2', '/3'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_event_ordering- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-03 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_groups_filtering_person_on_events- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'finance'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_groups_filtering_person_on_events.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'technology'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC,- toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_groups_filtering_person_on_events.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 1))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_1 ON equals(events.`$group_1`, events__group_1.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_1.properties___industry, 'technology'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC,- toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_person_dropoffs- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_step two'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_step three'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.5- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '4_step four'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_dropoffs.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_person_on_events_v2- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'poev2_p2'- '''-# ----# name: TestClickhousePaths.test_person_on_events_v2.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_recording- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_recording.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s3', 's1', 's5']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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- '''-# ----# name: TestClickhousePaths.test_recording_for_dropoff- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_recording_for_dropoff.1- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_recording_for_dropoff.2- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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- '''-# ----# name: TestClickhousePaths.test_recording_with_no_window_or_session_id- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_recording_with_no_window_or_session_id.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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- '''-# ----# name: TestClickhousePaths.test_recording_with_start_and_end- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM (- SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid,- session_id,- window_id)) AS matching_events,- count(*) AS event_count- FROM (- SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_',- ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index,- 1), 0), concat(ifNull(toString(minus(event_in_session_index,- 1)), ''), '_',- ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM (- SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic,- '')) AS path_basic_0,- arrayMap((x,- y) -> if(ifNull(equals(x,- y), isNull(x)- and isNull(y)), 0,- 1), path_basic,- path_basic_0) AS mapping,- arrayFilter((x,- y) -> y,- time,- mapping) AS timings,- arrayFilter((x,- y) -> y,- path_basic,- mapping) AS compact_path,- indexOf(compact_path,- '/3') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x,- y) -> y,- uuid_items,- mapping) AS uuid,- arrayFilter((x,- y) -> y,- timestamp_items,- mapping) AS timestamp,- arrayFilter((x,- y) -> y,- session_id_items,- mapping) AS session_id,- arrayFilter((x,- y) -> y,- window_id_items,- mapping) AS window_id,- indexOf(compact_path,- '/1') AS start_target_index,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(compact_path,- start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path,- '/3') AS end_target_index,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_path,- end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,- 1,- intDiv(5,- 2)), ['...'],- arraySlice(filtered_path,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(timings,- start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_timings,- end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,- 1,- intDiv(5,- 2)), [filtered_timings[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_timings,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(uuid,- start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_uuid,- end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,- 1,- intDiv(5,- 2)), [filtered_uuid[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_uuid,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_timestamp,- end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,- 1,- intDiv(5,- 2)), [filtered_timestamp[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_timestamp,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(session_id,- start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_session_id,- end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,- 1,- intDiv(5,- 2)), [filtered_session_id[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_session_id,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(window_id,- start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_window_id,- end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,- 1,- intDiv(5,- 2)), [filtered_window_id[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_window_id,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_',- ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path,- timings_diff,- arrayPopBack(arrayPushFront(limited_path,- '')), limited_uuid,- limited_timestamp,- limited_session_id,- limited_window_id) AS limited_path_timings- FROM (- SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list,- timing_list,- arrayDifference(timing_list), uuid_list,- timestamp_list,- session_id_list,- window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3,- 1800), 0), 0,- 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM (- SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM (- SELECT toTimeZone(events.timestamp,- 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id,- events.person_id) AS person_id,- ifNull(if(equals(events.event,- '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,- '$current_url'), ''), 'null'), '^"|"$',- ''), ''), '(.)/$',- '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp,- 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`,- ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`,- ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped,- NULL) AS group_index, (if(ifNull(greater(group_index,- 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id,- 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,- events__override.distinct_id)- WHERE and(equals(events.team_id,- 99999), and(greaterOrEquals(events.timestamp,- toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',- 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,- assumeNotNull(toDateTime('2012-01-02 23:59:59',- 'UTC')))), equals(events.event,- '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,- events.person_id) ASC, toTimeZone(events.timestamp,- 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index,- 0), 0), ifNull(greater(end_target_index,- 0), 0)))) WHERE ifNull(equals(path_key,- '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN (- SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at,- 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id,- 99999), in(id, (- SELECT source.actor_id AS actor_id- FROM (- SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid,- session_id,- window_id)) AS matching_events,- count(*) AS event_count- FROM (- SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_',- ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index,- 1), 0), concat(ifNull(toString(minus(event_in_session_index,- 1)), ''), '_',- ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM (- SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic,- '')) AS path_basic_0,- arrayMap((x,- y) -> if(ifNull(equals(x,- y), isNull(x)- and isNull(y)), 0,- 1), path_basic,- path_basic_0) AS mapping,- arrayFilter((x,- y) -> y,- time,- mapping) AS timings,- arrayFilter((x,- y) -> y,- path_basic,- mapping) AS compact_path,- indexOf(compact_path,- '/3') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x,- y) -> y,- uuid_items,- mapping) AS uuid,- arrayFilter((x,- y) -> y,- timestamp_items,- mapping) AS timestamp,- arrayFilter((x,- y) -> y,- session_id_items,- mapping) AS session_id,- arrayFilter((x,- y) -> y,- window_id_items,- mapping) AS window_id,- indexOf(compact_path,- '/1') AS start_target_index,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(compact_path,- start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path,- '/3') AS end_target_index,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_path,- end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,- 1,- intDiv(5,- 2)), ['...'],- arraySlice(filtered_path,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(timings,- start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_timings,- end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,- 1,- intDiv(5,- 2)), [filtered_timings[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_timings,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(uuid,- start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_uuid,- end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,- 1,- intDiv(5,- 2)), [filtered_uuid[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_uuid,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_timestamp,- end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,- 1,- intDiv(5,- 2)), [filtered_timestamp[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_timestamp,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(session_id,- start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_session_id,- end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,- 1,- intDiv(5,- 2)), [filtered_session_id[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_session_id,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index,- 0), 0), arraySlice(window_id,- start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index,- 0), 0), arrayResize(start_filtered_window_id,- end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,- 1,- intDiv(5,- 2)), [filtered_window_id[plus(1,- intDiv(5,- 2))]], arraySlice(filtered_window_id,- multiply(-1,- intDiv(5,- 2)), intDiv(5,- 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_',- ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path,- timings_diff,- arrayPopBack(arrayPushFront(limited_path,- '')), limited_uuid,- limited_timestamp,- limited_session_id,- limited_window_id) AS limited_path_timings- FROM (- SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list,- timing_list,- arrayDifference(timing_list), uuid_list,- timestamp_list,- session_id_list,- window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3,- 1800), 0), 0,- 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM (- SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM (- SELECT toTimeZone(events.timestamp,- 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id,- events.person_id) AS person_id,- ifNull(if(equals(events.event,- '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,- '$current_url'), ''), 'null'), '^"|"$',- ''), ''), '(.)/$',- '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp,- 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`,- ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`,- ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped,- NULL) AS group_index, (if(ifNull(greater(group_index,- 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides WHERE equals(person_distinct_id_overrides.team_id,- 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,- events__override.distinct_id)- WHERE and(equals(events.team_id,- 99999), and(greaterOrEquals(events.timestamp,- toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',- 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,- assumeNotNull(toDateTime('2012-01-02 23:59:59',- 'UTC')))), equals(events.event,- '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,- events.person_id) ASC, toTimeZone(events.timestamp,- 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index,- 0), 0), ifNull(greater(end_target_index,- 0), 0)))) WHERE ifNull(equals(path_key,- '2_/2'), 0)- GROUP BY person_id) AS source)))- 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,- 'UTC')), person.version), 1), plus(now64(6,- 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id,- source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_recording_with_start_and_end.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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- '''-# ----# name: TestClickhousePaths.test_respect_session_limits- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_start_and_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_start_and_end.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_start_and_end.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_start_and_end.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_start_and_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_start_and_end_materialized.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_start_and_end_materialized.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_start_and_end_materialized.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_start_dropping_orphaned_edges- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/2') AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_step_conversion_times- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_step_limit- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_step_limit.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_step_limit.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_step_limit.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_step_limit.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 3) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 3) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 3) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 3) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_step_limit.5- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_step_limit.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_step_limit.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_step_limit.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '3_/3'), 0), ifNull(equals(path_key, '4_/4'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePaths.test_wildcard_groups_across_people- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePaths.test_wildcard_groups_evil_input- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['(a+)+',- '[aaa|aaaa]+',- '1.*',- '.*',- '/3?q=1',- '/3*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['\\(a\\+\\)\\+', '\\[aaa\\|aaaa\\]\\+', '1\\..*', '\\..*', '/3\\?q=1', '/3.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_end.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_end_materialized.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, -5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, -5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), nullIf(nullIf(events.`mat_$screen_name`, ''), 'null'), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_exclusion_filters_with_wildcard_groups- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_exclusion_filters_with_wildcard_groups.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/xxx/invalid/*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/xxx/invalid/.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_inclusion_exclusion_filters- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_inclusion_exclusion_filters.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$screen'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_inclusion_exclusion_filters.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_inclusion_exclusion_filters.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))), notIn(path_item, ['/custom1', '/1', '/2', '/3'])))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_event_ordering- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-03 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_groups_filtering_person_on_events- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'finance'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_groups_filtering_person_on_events.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'technology'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_groups_filtering_person_on_events.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_id AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- FROM events- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 1))- GROUP BY groups.group_type_index,- groups.group_key) AS events__group_1 ON equals(events.`$group_1`, events__group_1.key)- WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_1.properties___industry, 'technology'), 0), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY events.person_id ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_step two'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '2_step two'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_step three'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.5- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '3_step three'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '4_step four'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_dropoffs.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(events.event, '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(last_path_key, '4_step four'), 0)- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_person_on_events_v2- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'poev2_p2'- '''-# ----# name: TestClickhousePathsUDF.test_person_on_events_v2.1- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_recording- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_recording.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s3', 's1', 's5']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_for_dropoff- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_for_dropoff.1- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)- and isNull(path_key)))- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_for_dropoff.2- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_with_no_window_or_session_id- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 5) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 5) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 5) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_with_no_window_or_session_id.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_with_start_and_end- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/3') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/1') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/3') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count- FROM- (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id- FROM- (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, '/3') AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, indexOf(compact_path, '/1') AS start_target_index, if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path, indexOf(start_filtered_path, '/3') AS end_target_index, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path, if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path, if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings, if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings, if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid, if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid, if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp, if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp, if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id, if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id, if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id, if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id, if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE ifNull(equals(path_key, '2_/2'), 0)- GROUP BY person_id) AS source)))- 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_recording_with_start_and_end.1- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))- GROUP BY session_replay_events.session_id- HAVING ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 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- '''-# ----# name: TestClickhousePathsUDF.test_respect_session_limits- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end_materialized- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end_materialized.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/5') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end_materialized.2- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_start_and_end_materialized.3- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/about') AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- indexOf(compact_path, '/2') AS start_target_index,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,- indexOf(start_filtered_path, '/about') AS end_target_index,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,- if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,- if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,- if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,- if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,- if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,- if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,- if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,- if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(nullIf(nullIf(events.`mat_$current_url`, ''), 'null'), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))- WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_start_dropping_orphaned_edges- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, '/2') AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index- WHERE ifNull(greater(target_index, 0), 0)))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_step_conversion_times- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_step_limit- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.1- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.2- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 2) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 2) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 2) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 2) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 2) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.3- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.4- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 3) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 3) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 3) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 3) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 3) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 3) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.5- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.6- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.7- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_step_limit.8- '''- SELECT source.id AS id- FROM- (SELECT person_id AS actor_id,- groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,- count(*) AS event_count,- actor_id AS id- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key,- final_uuid AS uuid,- final_timestamp AS timestamp,- final_session_id AS session_id,- final_window_id AS window_id- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- joined_path_tuple.4 AS final_uuid,- joined_path_tuple.5 AS final_timestamp,- joined_path_tuple.6 AS final_session_id,- joined_path_tuple.7 AS final_window_id,- arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,- arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,- arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,- arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,- arraySlice(filtered_uuid, 1, 4) AS limited_uuid,- if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,- arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,- if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,- arraySlice(filtered_session_id, 1, 4) AS limited_session_id,- if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,- arraySlice(filtered_window_id, 1, 4) AS limited_window_id,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,- path_time_tuple.4 AS uuid_items,- path_time_tuple.5 AS timestamp_items,- path_time_tuple.6 AS session_id_items,- path_time_tuple.7 AS window_id_items- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list,- groupArray(uuid) AS uuid_list,- groupArray(timestamp) AS timestamp_list,- groupArray(session_id) AS session_id_list,- groupArray(window_id) AS window_id_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,- events.uuid AS uuid,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,- ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,- NULL AS groupings,- multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE and(ifNull(equals(last_path_key, '3_/3'), 0), ifNull(equals(path_key, '4_/4'), 0))- GROUP BY person_id) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- 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- '''-# ----# name: TestClickhousePathsUDF.test_wildcard_groups_across_people- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 4) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 4) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['/bar/*/foo'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhousePathsUDF.test_wildcard_groups_evil_input- '''- SELECT last_path_key AS source_event,- path_key AS target_event,- count(*) AS event_count,- avg(conversion_time) AS average_conversion_time- FROM- (SELECT person_id AS person_id,- path AS path,- conversion_time AS conversion_time,- event_in_session_index AS event_in_session_index,- concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,- if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,- path_dropoff_key AS path_dropoff_key- FROM- (SELECT person_id AS person_id,- joined_path_tuple.1 AS path,- joined_path_tuple.2 AS conversion_time,- joined_path_tuple.3 AS prev_path,- event_in_session_index,- session_index AS session_index,- arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,- arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)- and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,- arrayFilter((x, y) -> y, time, mapping) AS timings,- arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,- indexOf(compact_path, NULL) AS target_index,- if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,- arraySlice(filtered_path, 1, 5) AS limited_path,- if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,- arraySlice(filtered_timings, 1, 5) AS limited_timings,- arrayDifference(limited_timings) AS timings_diff,- concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,- arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings- FROM- (SELECT person_id AS person_id,- path_time_tuple.1 AS path_basic,- path_time_tuple.2 AS time,- session_index,- arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,- arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths- FROM- (SELECT person_id AS person_id,- groupArray(timestamp) AS timing_list,- groupArray(path_item) AS path_list- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,- ['(a+)+',- '[aaa|aaaa]+',- '1.*',- '.*',- '/3?q=1',- '/3*'] AS groupings,- multiMatchAnyIndex(path_item_ungrouped, ['\\(a\\+\\)\\+', '\\[aaa\\|aaaa\\]\\+', '1\\..*', '\\..*', '/3\\?q=1', '/3.*']) AS group_index,- (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item- 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- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))- ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)- GROUP BY person_id) ARRAY- JOIN session_paths AS path_time_tuple,- arrayEnumerate(session_paths) AS session_index) ARRAY- JOIN limited_path_timings AS joined_path_tuple,- arrayEnumerate(limited_path_timings) AS event_in_session_index))- WHERE isNotNull(source_event)- GROUP BY source_event,- target_event- ORDER BY event_count DESC,- source_event ASC,- target_event ASC- LIMIT 50 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.pyindex 790c5884a766..f7b0120d1278 100644--- a/posthog/hogql_queries/query_runner.py+++ b/posthog/hogql_queries/query_runner.py@@ -378,7 +378,7 @@ def get_query_runner(modifiers=modifiers,)if kind == "PathsQuery":- from .insights.paths.paths_query_runner import PathsQueryRunner+ from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunnerreturn PathsQueryRunner(query=cast(PathsQuery | dict[str, Any], query),diff --git a/posthog/hogql_queries/insights/paths/__init__.py b/products/product_analytics/backend/hogql_queries/__init__.pysimilarity index 100%rename from posthog/hogql_queries/insights/paths/__init__.pyrename to products/product_analytics/backend/hogql_queries/__init__.pydiff --git a/posthog/hogql_queries/insights/paths/test/__init__.py b/products/product_analytics/backend/hogql_queries/paths/__init__.pysimilarity index 100%rename from posthog/hogql_queries/insights/paths/test/__init__.pyrename to products/product_analytics/backend/hogql_queries/paths/__init__.pydiff --git a/posthog/hogql_queries/insights/paths/paths_query_runner.py b/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.pysimilarity index 100%rename from posthog/hogql_queries/insights/paths/paths_query_runner.pyrename to products/product_analytics/backend/hogql_queries/paths/paths_query_runner.pydiff --git a/products/product_analytics/backend/hogql_queries/paths/test/__init__.py b/products/product_analytics/backend/hogql_queries/paths/test/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr b/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambrnew file mode 100644index 000000000000..d4e485f2104c--- /dev/null+++ b/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr@@ -0,0 +1,5293 @@+# serializer version: 1+# name: TestClickhousePaths.test_end+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, -5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, -5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE ifNull(greater(target_index, 0), 0)))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_end.1+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ if(ifNull(greater(target_index, 0), 0), arrayResize(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, -5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arrayResize(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, -5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE ifNull(greater(target_index, 0), 0)))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_exclusion_filters_with_wildcard_groups+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ ['/bar/*/foo'] AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_exclusion_filters_with_wildcard_groups.1+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ ['/xxx/invalid/*'] AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, ['/xxx/invalid/.*']) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(equals(events.event, '$pageview'), notIn(path_item, ['/bar/*/foo'])))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_inclusion_exclusion_filters+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.1+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), events.event), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$screen'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.2+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_inclusion_exclusion_filters.3+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), and(or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))), notIn(path_item, ['/custom1', '/1', '/2', '/3'])))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_event_ordering+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-03 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_groups_filtering_person_on_events+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,+ groups.group_type_index AS index,+ groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 0))+ GROUP BY groups.group_type_index,+ groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)+ WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'finance'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_groups_filtering_person_on_events.1+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ events.person_id AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ FROM events+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,+ groups.group_type_index AS index,+ groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 0))+ GROUP BY groups.group_type_index,+ groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)+ WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_0.properties___industry, 'technology'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))+ ORDER BY events.person_id ASC,+ toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_groups_filtering_person_on_events.2+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ events.person_id AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ FROM events+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,+ groups.group_type_index AS index,+ groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 1))+ GROUP BY groups.group_type_index,+ groups.group_key) AS events__group_1 ON equals(events.`$group_1`, events__group_1.key)+ WHERE and(equals(events.team_id, 99999), ifNull(equals(events__group_1.properties___industry, 'technology'), 0), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))+ ORDER BY events.person_id ASC,+ toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '2_step two'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.1+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '2_step two'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.2+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(last_path_key, '2_step two'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.3+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '3_step three'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.4+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '3_step three'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.5+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(last_path_key, '3_step three'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.6+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '4_step four'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.7+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '4_step four'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_dropoffs.8+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(events.event, '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), not(startsWith(events.event, '$')))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(last_path_key, '4_step four'), 0)+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_person_on_events_v2+ '''++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'poev2_p2'+ '''+# ---+# name: TestClickhousePaths.test_person_on_events_v2.1+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-02-01 23:59:59', 'UTC')))), or(equals(events.event, '$pageview'), equals(events.event, '$screen'), not(startsWith(events.event, '$'))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_recording+ '''+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '2_/2'), 0)+ GROUP BY person_id) AS source+ INNER JOIN+ (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,+ person.id AS id+ FROM person+ WHERE and(equals(person.team_id, 99999), in(id,+ (SELECT source.actor_id AS actor_id+ FROM+ (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count+ FROM+ (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '2_/2'), 0)+ GROUP BY person_id) AS source)))+ 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY persons.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_recording.1+ '''+ SELECT session_replay_events.session_id AS session_id,+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,+ max(session_replay_events.retention_period_days) AS retention_period_days,+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time+ FROM session_replay_events+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s3', 's1', 's5']))+ GROUP BY session_replay_events.session_id+ HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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+ '''+# ---+# name: TestClickhousePaths.test_recording_for_dropoff+ '''+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source+ INNER JOIN+ (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,+ person.id AS id+ FROM person+ WHERE and(equals(person.team_id, 99999), in(id,+ (SELECT source.actor_id AS actor_id+ FROM+ (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count+ FROM+ (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '2_/2'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source)))+ 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY persons.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_recording_for_dropoff.1+ '''+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source+ INNER JOIN+ (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,+ person.id AS id+ FROM person+ WHERE and(equals(person.team_id, 99999), in(id,+ (SELECT source.actor_id AS actor_id+ FROM+ (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count+ FROM+ (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(path_dropoff_key, '3_/3'), 0), ifNull(equals(path_dropoff_key, path_key), isNull(path_dropoff_key)+ and isNull(path_key)))+ GROUP BY person_id) AS source)))+ 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY persons.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_recording_for_dropoff.2+ '''+ SELECT session_replay_events.session_id AS session_id,+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,+ max(session_replay_events.retention_period_days) AS retention_period_days,+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time+ FROM session_replay_events+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))+ GROUP BY session_replay_events.session_id+ HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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+ '''+# ---+# name: TestClickhousePaths.test_recording_with_no_window_or_session_id+ '''+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 5) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 5) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 5) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '2_/2'), 0)+ GROUP BY person_id) AS source+ INNER JOIN+ (SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1) AS created_at,+ person.id AS id+ FROM person+ WHERE and(equals(person.team_id, 99999), in(id,+ (SELECT source.actor_id AS actor_id+ FROM+ (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count+ FROM+ (SELECT person_id AS person_id, path AS path, conversion_time AS conversion_time, event_in_session_index AS event_in_session_index, concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key, if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key, path_dropoff_key AS path_dropoff_key, final_uuid AS uuid, final_timestamp AS timestamp, final_session_id AS session_id, final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id, joined_path_tuple.1 AS path, joined_path_tuple.2 AS conversion_time, joined_path_tuple.3 AS prev_path, event_in_session_index, session_index AS session_index, arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0, arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping, arrayFilter((x, y) -> y, time, mapping) AS timings, arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path, indexOf(compact_path, NULL) AS target_index, joined_path_tuple.4 AS final_uuid, joined_path_tuple.5 AS final_timestamp, joined_path_tuple.6 AS final_session_id, joined_path_tuple.7 AS final_window_id, arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid, arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp, arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id, arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id, if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path, arraySlice(filtered_path, 1, 5) AS limited_path, if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings, arraySlice(filtered_timings, 1, 5) AS limited_timings, if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid, arraySlice(filtered_uuid, 1, 5) AS limited_uuid, if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp, arraySlice(filtered_timestamp, 1, 5) AS limited_timestamp, if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id, arraySlice(filtered_session_id, 1, 5) AS limited_session_id, if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id, arraySlice(filtered_window_id, 1, 5) AS limited_window_id, arrayDifference(limited_timings) AS timings_diff, concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key, arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id, path_time_tuple.1 AS path_basic, path_time_tuple.2 AS time, session_index, arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple, arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths, path_time_tuple.4 AS uuid_items, path_time_tuple.5 AS timestamp_items, path_time_tuple.6 AS session_id_items, path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id, groupArray(timestamp) AS timing_list, groupArray(path_item) AS path_list, groupArray(uuid) AS uuid_list, groupArray(timestamp) AS timestamp_list, groupArray(session_id) AS session_id_list, groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped, events.uuid AS uuid, toTimeZone(events.timestamp, 'UTC') AS timestamp, ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id, ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id, NULL AS groupings, multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index, (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-02 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple, arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE ifNull(equals(path_key, '2_/2'), 0)+ GROUP BY person_id) AS source)))+ 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, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY persons.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_recording_with_no_window_or_session_id.1+ '''+ SELECT session_replay_events.session_id AS session_id,+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,+ max(session_replay_events.retention_period_days) AS retention_period_days,+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time+ FROM session_replay_events+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))+ GROUP BY session_replay_events.session_id+ HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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+ '''+# ---+# name: TestClickhousePaths.test_recording_with_start_and_end+ '''+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events+ FROM (+ SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid,+ session_id,+ window_id)) AS matching_events,+ count(*) AS event_count+ FROM (+ SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_',+ ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index,+ 1), 0), concat(ifNull(toString(minus(event_in_session_index,+ 1)), ''), '_',+ ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM (+ SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic,+ '')) AS path_basic_0,+ arrayMap((x,+ y) -> if(ifNull(equals(x,+ y), isNull(x)+ and isNull(y)), 0,+ 1), path_basic,+ path_basic_0) AS mapping,+ arrayFilter((x,+ y) -> y,+ time,+ mapping) AS timings,+ arrayFilter((x,+ y) -> y,+ path_basic,+ mapping) AS compact_path,+ indexOf(compact_path,+ '/3') AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x,+ y) -> y,+ uuid_items,+ mapping) AS uuid,+ arrayFilter((x,+ y) -> y,+ timestamp_items,+ mapping) AS timestamp,+ arrayFilter((x,+ y) -> y,+ session_id_items,+ mapping) AS session_id,+ arrayFilter((x,+ y) -> y,+ window_id_items,+ mapping) AS window_id,+ indexOf(compact_path,+ '/1') AS start_target_index,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(compact_path,+ start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path,+ '/3') AS end_target_index,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_path,+ end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,+ 1,+ intDiv(5,+ 2)), ['...'],+ arraySlice(filtered_path,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(timings,+ start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_timings,+ end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,+ 1,+ intDiv(5,+ 2)), [filtered_timings[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_timings,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_timings) AS limited_timings,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(uuid,+ start_target_index), uuid) AS start_filtered_uuid,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_uuid,+ end_target_index), start_filtered_uuid) AS filtered_uuid,+ if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,+ 1,+ intDiv(5,+ 2)), [filtered_uuid[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_uuid,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_uuid) AS limited_uuid,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_timestamp,+ end_target_index), start_filtered_timestamp) AS filtered_timestamp,+ if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,+ 1,+ intDiv(5,+ 2)), [filtered_timestamp[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_timestamp,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_timestamp) AS limited_timestamp,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(session_id,+ start_target_index), session_id) AS start_filtered_session_id,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_session_id,+ end_target_index), start_filtered_session_id) AS filtered_session_id,+ if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,+ 1,+ intDiv(5,+ 2)), [filtered_session_id[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_session_id,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_session_id) AS limited_session_id,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(window_id,+ start_target_index), window_id) AS start_filtered_window_id,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_window_id,+ end_target_index), start_filtered_window_id) AS filtered_window_id,+ if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,+ 1,+ intDiv(5,+ 2)), [filtered_window_id[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_window_id,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_window_id) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_',+ ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path,+ timings_diff,+ arrayPopBack(arrayPushFront(limited_path,+ '')), limited_uuid,+ limited_timestamp,+ limited_session_id,+ limited_window_id) AS limited_path_timings+ FROM (+ SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list,+ timing_list,+ arrayDifference(timing_list), uuid_list,+ timestamp_list,+ session_id_list,+ window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3,+ 1800), 0), 0,+ 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM (+ SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM (+ SELECT toTimeZone(events.timestamp,+ 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id,+ events.person_id) AS person_id,+ ifNull(if(equals(events.event,+ '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,+ '$current_url'), ''), 'null'), '^"|"$',+ ''), ''), '(.)/$',+ '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp,+ 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`,+ ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`,+ ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped,+ NULL) AS group_index, (if(ifNull(greater(group_index,+ 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id,+ 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,+ events__override.distinct_id)+ WHERE and(equals(events.team_id,+ 99999), and(greaterOrEquals(events.timestamp,+ toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',+ 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,+ assumeNotNull(toDateTime('2012-01-02 23:59:59',+ 'UTC')))), equals(events.event,+ '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,+ events.person_id) ASC, toTimeZone(events.timestamp,+ 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index,+ 0), 0), ifNull(greater(end_target_index,+ 0), 0)))) WHERE ifNull(equals(path_key,+ '2_/2'), 0)+ GROUP BY person_id) AS source+ INNER JOIN (+ SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at,+ 'UTC')), person.version), 1) AS created_at,+ person.id AS id+ FROM person+ WHERE and(equals(person.team_id,+ 99999), in(id, (+ SELECT source.actor_id AS actor_id+ FROM (+ SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid,+ session_id,+ window_id)) AS matching_events,+ count(*) AS event_count+ FROM (+ SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_',+ ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index,+ 1), 0), concat(ifNull(toString(minus(event_in_session_index,+ 1)), ''), '_',+ ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM (+ SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic,+ '')) AS path_basic_0,+ arrayMap((x,+ y) -> if(ifNull(equals(x,+ y), isNull(x)+ and isNull(y)), 0,+ 1), path_basic,+ path_basic_0) AS mapping,+ arrayFilter((x,+ y) -> y,+ time,+ mapping) AS timings,+ arrayFilter((x,+ y) -> y,+ path_basic,+ mapping) AS compact_path,+ indexOf(compact_path,+ '/3') AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x,+ y) -> y,+ uuid_items,+ mapping) AS uuid,+ arrayFilter((x,+ y) -> y,+ timestamp_items,+ mapping) AS timestamp,+ arrayFilter((x,+ y) -> y,+ session_id_items,+ mapping) AS session_id,+ arrayFilter((x,+ y) -> y,+ window_id_items,+ mapping) AS window_id,+ indexOf(compact_path,+ '/1') AS start_target_index,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(compact_path,+ start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path,+ '/3') AS end_target_index,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_path,+ end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,+ 1,+ intDiv(5,+ 2)), ['...'],+ arraySlice(filtered_path,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(timings,+ start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_timings,+ end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,+ 1,+ intDiv(5,+ 2)), [filtered_timings[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_timings,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_timings) AS limited_timings,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(uuid,+ start_target_index), uuid) AS start_filtered_uuid,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_uuid,+ end_target_index), start_filtered_uuid) AS filtered_uuid,+ if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,+ 1,+ intDiv(5,+ 2)), [filtered_uuid[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_uuid,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_uuid) AS limited_uuid,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_timestamp,+ end_target_index), start_filtered_timestamp) AS filtered_timestamp,+ if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,+ 1,+ intDiv(5,+ 2)), [filtered_timestamp[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_timestamp,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_timestamp) AS limited_timestamp,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(session_id,+ start_target_index), session_id) AS start_filtered_session_id,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_session_id,+ end_target_index), start_filtered_session_id) AS filtered_session_id,+ if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,+ 1,+ intDiv(5,+ 2)), [filtered_session_id[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_session_id,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_session_id) AS limited_session_id,+ if(ifNull(greater(start_target_index,+ 0), 0), arraySlice(window_id,+ start_target_index), window_id) AS start_filtered_window_id,+ if(ifNull(greater(end_target_index,+ 0), 0), arrayResize(start_filtered_window_id,+ end_target_index), start_filtered_window_id) AS filtered_window_id,+ if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,+ 1,+ intDiv(5,+ 2)), [filtered_window_id[plus(1,+ intDiv(5,+ 2))]], arraySlice(filtered_window_id,+ multiply(-1,+ intDiv(5,+ 2)), intDiv(5,+ 2))), filtered_window_id) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_',+ ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path,+ timings_diff,+ arrayPopBack(arrayPushFront(limited_path,+ '')), limited_uuid,+ limited_timestamp,+ limited_session_id,+ limited_window_id) AS limited_path_timings+ FROM (+ SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list,+ timing_list,+ arrayDifference(timing_list), uuid_list,+ timestamp_list,+ session_id_list,+ window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3,+ 1800), 0), 0,+ 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM (+ SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM (+ SELECT toTimeZone(events.timestamp,+ 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id,+ events.person_id) AS person_id,+ ifNull(if(equals(events.event,+ '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,+ '$current_url'), ''), 'null'), '^"|"$',+ ''), ''), '(.)/$',+ '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp,+ 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`,+ ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`,+ ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped,+ NULL) AS group_index, (if(ifNull(greater(group_index,+ 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides WHERE equals(person_distinct_id_overrides.team_id,+ 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,+ events__override.distinct_id)+ WHERE and(equals(events.team_id,+ 99999), and(greaterOrEquals(events.timestamp,+ toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',+ 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,+ assumeNotNull(toDateTime('2012-01-02 23:59:59',+ 'UTC')))), equals(events.event,+ '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,+ events.person_id) ASC, toTimeZone(events.timestamp,+ 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index,+ 0), 0), ifNull(greater(end_target_index,+ 0), 0)))) WHERE ifNull(equals(path_key,+ '2_/2'), 0)+ GROUP BY person_id) AS source)))+ 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,+ 'UTC')), person.version), 1), plus(now64(6,+ 'UTC'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id,+ source.actor_id)+ ORDER BY persons.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_recording_with_start_and_end.1+ '''+ SELECT session_replay_events.session_id AS session_id,+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,+ max(session_replay_events.retention_period_days) AS retention_period_days,+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time+ FROM session_replay_events+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))+ GROUP BY session_replay_events.session_id+ HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 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+ '''+# ---+# name: TestClickhousePaths.test_respect_session_limits+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_start_and_end+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ indexOf(compact_path, '/5') AS start_target_index,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path, '/about') AS end_target_index,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_start_and_end.1+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ indexOf(compact_path, '/5') AS start_target_index,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path, '/about') AS end_target_index,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(5, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(5, 2)), [filtered_timings[plus(1, intDiv(5, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timings) AS limited_timings,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,+ if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(5, 2)), [filtered_uuid[plus(1, intDiv(5, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_uuid) AS limited_uuid,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,+ if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(5, 2)), [filtered_timestamp[plus(1, intDiv(5, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_timestamp) AS limited_timestamp,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,+ if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(5, 2)), [filtered_session_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_session_id) AS limited_session_id,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,+ if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(5, 2)), [filtered_window_id[plus(1, intDiv(5, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(5, 2)), intDiv(5, 2))), filtered_window_id) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))+ WHERE and(ifNull(equals(last_path_key, '1_/5'), 0), ifNull(equals(path_key, '2_/about'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_start_and_end.2+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ indexOf(compact_path, '/2') AS start_target_index,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path, '/about') AS end_target_index,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_start_and_end.3+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/about') AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ indexOf(compact_path, '/2') AS start_target_index,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(compact_path, start_target_index), compact_path) AS start_filtered_path,+ indexOf(start_filtered_path, '/about') AS end_target_index,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_path, end_target_index), start_filtered_path) AS filtered_path,+ if(ifNull(greater(length(filtered_path), 4), 0), arrayConcat(arraySlice(filtered_path, 1, intDiv(4, 2)), ['...'], arraySlice(filtered_path, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_path) AS limited_path,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timings, start_target_index), timings) AS start_filtered_timings,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timings, end_target_index), start_filtered_timings) AS filtered_timings,+ if(ifNull(greater(length(filtered_timings), 4), 0), arrayConcat(arraySlice(filtered_timings, 1, intDiv(4, 2)), [filtered_timings[plus(1, intDiv(4, 2))]], arraySlice(filtered_timings, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timings) AS limited_timings,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(uuid, start_target_index), uuid) AS start_filtered_uuid,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_uuid, end_target_index), start_filtered_uuid) AS filtered_uuid,+ if(ifNull(greater(length(filtered_uuid), 4), 0), arrayConcat(arraySlice(filtered_uuid, 1, intDiv(4, 2)), [filtered_uuid[plus(1, intDiv(4, 2))]], arraySlice(filtered_uuid, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_uuid) AS limited_uuid,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_timestamp, end_target_index), start_filtered_timestamp) AS filtered_timestamp,+ if(ifNull(greater(length(filtered_timestamp), 4), 0), arrayConcat(arraySlice(filtered_timestamp, 1, intDiv(4, 2)), [filtered_timestamp[plus(1, intDiv(4, 2))]], arraySlice(filtered_timestamp, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_timestamp) AS limited_timestamp,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(session_id, start_target_index), session_id) AS start_filtered_session_id,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_session_id, end_target_index), start_filtered_session_id) AS filtered_session_id,+ if(ifNull(greater(length(filtered_session_id), 4), 0), arrayConcat(arraySlice(filtered_session_id, 1, intDiv(4, 2)), [filtered_session_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_session_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_session_id) AS limited_session_id,+ if(ifNull(greater(start_target_index, 0), 0), arraySlice(window_id, start_target_index), window_id) AS start_filtered_window_id,+ if(ifNull(greater(end_target_index, 0), 0), arrayResize(start_filtered_window_id, end_target_index), start_filtered_window_id) AS filtered_window_id,+ if(ifNull(greater(length(filtered_window_id), 4), 0), arrayConcat(arraySlice(filtered_window_id, 1, intDiv(4, 2)), [filtered_window_id[plus(1, intDiv(4, 2))]], arraySlice(filtered_window_id, multiply(-1, intDiv(4, 2)), intDiv(4, 2))), filtered_window_id) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE and(ifNull(greater(start_target_index, 0), 0), ifNull(greater(end_target_index, 0), 0))))+ WHERE and(ifNull(equals(last_path_key, '3_...'), 0), ifNull(equals(path_key, '4_/5'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_start_dropping_orphaned_edges+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, '/2') AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2021-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2021-05-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index+ WHERE ifNull(greater(target_index, 0), 0)))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_step_conversion_times+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_step_limit+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 2) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 2) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_step_limit.1+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 2) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 2) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 2) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 2) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 2) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_step_limit.2+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 2) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 2) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 2) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 2) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 2) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 2) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_step_limit.3+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 3) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 3) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_step_limit.4+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 3) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 3) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 3) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 3) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 3) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 3) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_step_limit.5+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_step_limit.6+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 4) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 4) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 4) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '1_/1'), 0), ifNull(equals(path_key, '2_/2'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_step_limit.7+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 4) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 4) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 4) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '2_/2'), 0), ifNull(equals(path_key, '3_/3'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_step_limit.8+ '''+ SELECT source.id AS id+ FROM+ (SELECT person_id AS actor_id,+ groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events,+ count(*) AS event_count,+ actor_id AS id+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key,+ final_uuid AS uuid,+ final_timestamp AS timestamp,+ final_session_id AS session_id,+ final_window_id AS window_id+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ joined_path_tuple.4 AS final_uuid,+ joined_path_tuple.5 AS final_timestamp,+ joined_path_tuple.6 AS final_session_id,+ joined_path_tuple.7 AS final_window_id,+ arrayFilter((x, y) -> y, uuid_items, mapping) AS uuid,+ arrayFilter((x, y) -> y, timestamp_items, mapping) AS timestamp,+ arrayFilter((x, y) -> y, session_id_items, mapping) AS session_id,+ arrayFilter((x, y) -> y, window_id_items, mapping) AS window_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ if(ifNull(greater(target_index, 0), 0), arraySlice(uuid, target_index), uuid) AS filtered_uuid,+ arraySlice(filtered_uuid, 1, 4) AS limited_uuid,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timestamp, target_index), timestamp) AS filtered_timestamp,+ arraySlice(filtered_timestamp, 1, 4) AS limited_timestamp,+ if(ifNull(greater(target_index, 0), 0), arraySlice(session_id, target_index), session_id) AS filtered_session_id,+ arraySlice(filtered_session_id, 1, 4) AS limited_session_id,+ if(ifNull(greater(target_index, 0), 0), arraySlice(window_id, target_index), window_id) AS filtered_window_id,+ arraySlice(filtered_window_id, 1, 4) AS limited_window_id,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, '')), limited_uuid, limited_timestamp, limited_session_id, limited_window_id) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list), uuid_list, timestamp_list, session_id_list, window_id_list) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths,+ path_time_tuple.4 AS uuid_items,+ path_time_tuple.5 AS timestamp_items,+ path_time_tuple.6 AS session_id_items,+ path_time_tuple.7 AS window_id_items+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list,+ groupArray(uuid) AS uuid_list,+ groupArray(timestamp) AS timestamp_list,+ groupArray(session_id) AS session_id_list,+ groupArray(window_id) AS window_id_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$screen'), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$screen_name'), ''), 'null'), '^"|"$', ''), if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event)), '') AS path_item_ungrouped,+ events.uuid AS uuid,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ ifNull(nullIf(nullIf(events.`$session_id`, ''), 'null'), '') AS session_id,+ ifNull(nullIf(nullIf(events.`$window_id`, ''), 'null'), '') AS window_id,+ NULL AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, NULL) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2011-12-31 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2012-01-07 23:59:59', 'UTC')))))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE and(ifNull(equals(last_path_key, '3_/3'), 0), ifNull(equals(path_key, '4_/4'), 0))+ GROUP BY person_id) AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ 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+ '''+# ---+# name: TestClickhousePaths.test_wildcard_groups_across_people+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 4) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 4) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ ['/bar/*/foo'] AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, ['/bar/.*/foo']) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhousePaths.test_wildcard_groups_evil_input+ '''+ SELECT last_path_key AS source_event,+ path_key AS target_event,+ count(*) AS event_count,+ avg(conversion_time) AS average_conversion_time+ FROM+ (SELECT person_id AS person_id,+ path AS path,+ conversion_time AS conversion_time,+ event_in_session_index AS event_in_session_index,+ concat(ifNull(toString(event_in_session_index), ''), '_', ifNull(toString(path), '')) AS path_key,+ if(ifNull(greater(event_in_session_index, 1), 0), concat(ifNull(toString(minus(event_in_session_index, 1)), ''), '_', ifNull(toString(prev_path), '')), NULL) AS last_path_key,+ path_dropoff_key AS path_dropoff_key+ FROM+ (SELECT person_id AS person_id,+ joined_path_tuple.1 AS path,+ joined_path_tuple.2 AS conversion_time,+ joined_path_tuple.3 AS prev_path,+ event_in_session_index,+ session_index AS session_index,+ arrayPopFront(arrayPushBack(path_basic, '')) AS path_basic_0,+ arrayMap((x, y) -> if(ifNull(equals(x, y), isNull(x)+ and isNull(y)), 0, 1), path_basic, path_basic_0) AS mapping,+ arrayFilter((x, y) -> y, time, mapping) AS timings,+ arrayFilter((x, y) -> y, path_basic, mapping) AS compact_path,+ indexOf(compact_path, NULL) AS target_index,+ if(ifNull(greater(target_index, 0), 0), arraySlice(compact_path, target_index), compact_path) AS filtered_path,+ arraySlice(filtered_path, 1, 5) AS limited_path,+ if(ifNull(greater(target_index, 0), 0), arraySlice(timings, target_index), timings) AS filtered_timings,+ arraySlice(filtered_timings, 1, 5) AS limited_timings,+ arrayDifference(limited_timings) AS timings_diff,+ concat(ifNull(toString(length(limited_path)), ''), '_', ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,+ arrayZip(limited_path, timings_diff, arrayPopBack(arrayPushFront(limited_path, ''))) AS limited_path_timings+ FROM+ (SELECT person_id AS person_id,+ path_time_tuple.1 AS path_basic,+ path_time_tuple.2 AS time,+ session_index,+ arrayZip(path_list, timing_list, arrayDifference(timing_list)) AS paths_tuple,+ arraySplit(x -> if(ifNull(less(x.3, 1800), 0), 0, 1), paths_tuple) AS session_paths+ FROM+ (SELECT person_id AS person_id,+ groupArray(timestamp) AS timing_list,+ groupArray(path_item) AS path_list+ FROM+ (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ ifNull(if(equals(events.event, '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), ''), '(.)/$', '\\1'), events.event), '') AS path_item_ungrouped,+ ['(a+)+',+ '[aaa|aaaa]+',+ '1.*',+ '.*',+ '/3?q=1',+ '/3*'] AS groupings,+ multiMatchAnyIndex(path_item_ungrouped, ['\\(a\\+\\)\\+', '\\[aaa\\|aaaa\\]\\+', '1\\..*', '\\..*', '/3\\?q=1', '/3.*']) AS group_index,+ (if(ifNull(greater(group_index, 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item+ 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+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-05-23 23:59:59', 'UTC')))), equals(events.event, '$pageview'))+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) ASC, toTimeZone(events.timestamp, 'UTC') ASC)+ GROUP BY person_id) ARRAY+ JOIN session_paths AS path_time_tuple,+ arrayEnumerate(session_paths) AS session_index) ARRAY+ JOIN limited_path_timings AS joined_path_tuple,+ arrayEnumerate(limited_path_timings) AS event_in_session_index))+ WHERE isNotNull(source_event)+ GROUP BY source_event,+ target_event+ ORDER BY event_count DESC,+ source_event ASC,+ target_event ASC+ LIMIT 50 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=23622320128,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---diff --git a/posthog/hogql_queries/insights/paths/test/test_paths_query_runner.py b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.pysimilarity index 99%rename from posthog/hogql_queries/insights/paths/test/test_paths_query_runner.pyrename to products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.pyindex 3a93f682d8a8..a47dad315ff4 100644--- a/posthog/hogql_queries/insights/paths/test/test_paths_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.py@@ -15,9 +15,10 @@ from dateutil.relativedelta import relativedeltafrom posthog.schema import CachedPathsQueryResponse-from posthog.hogql_queries.insights.paths.paths_query_runner import PathsQueryRunnerfrom posthog.models import Team+from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner+# This test file uses a batched method of event creation# We collect all events per test into an array and batch create the events to reduce creation timediff --git a/posthog/hogql_queries/insights/paths/test/test_paths_query_runner_ee.py b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.pysimilarity index 99%rename from posthog/hogql_queries/insights/paths/test/test_paths_query_runner_ee.pyrename to products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.pyindex f5377191dc88..f61b8f7d8184 100644--- a/posthog/hogql_queries/insights/paths/test/test_paths_query_runner_ee.py+++ b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py@@ -24,12 +24,13 @@ from posthog.schema import CachedPathsQueryResponse, PathsLinkfrom posthog.constants import FUNNEL_PATH_BETWEEN_STEPS, INSIGHT_FUNNELSfrom posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.paths.paths_query_runner import PathsQueryRunnerfrom posthog.models.group.util import create_groupfrom posthog.models.instance_setting import override_instance_configfrom posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summaryfrom posthog.test.test_utils import create_group_type_mapping_without_created_at+from products.product_analytics.backend.hogql_queries.paths.paths_query_runner import PathsQueryRunner+ONE_MINUTE = 60_000 # 1 minute in millisecondsdiff --git a/products/product_analytics/package.json b/products/product_analytics/package.jsonindex 5855cfa5afe4..c569651a72cc 100644--- a/products/product_analytics/package.json+++ b/products/product_analytics/package.json@@ -1,7 +1,7 @@{"name": "@posthog/products-product-analytics","scripts": {- "backend:test": "echo 'No backend tests'"+ "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short"},"dependencies": {"kea": "catalog:",diff --git a/products/ruff.toml b/products/ruff.tomlindex 161504ad46b1..949352effc05 100644--- a/products/ruff.toml+++ b/products/ruff.toml@@ -33,6 +33,7 @@ extend-select = ["ANN001", "ANN201", "ANN202", "ANN204"]"marketing_analytics/backend/**" = ["ANN"]"messaging/backend/**" = ["ANN"]"notebooks/backend/**" = ["ANN"]+"product_analytics/backend/**" = ["ANN"]"product_tours/backend/**" = ["ANN"]"revenue_analytics/backend/**" = ["ANN"]"signals/backend/**" = ["ANN"]diff --git a/tach.toml b/tach.tomlindex f4b49984a234..4a4d8ccf2e7a 100644--- a/tach.toml+++ b/tach.toml@@ -86,6 +86,7 @@ depends_on = ["products.notebooks","products.notifications","products.posthog_ai",+ "products.product_analytics","products.product_tours","products.replay_vision","products.revenue_analytics",@@ -378,7 +379,9 @@ layer = "modules"[[modules]]path = "products.product_analytics"-depends_on = []+depends_on = [+ "posthog",+]layer = "modules"[[modules]]