: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
fix(revenue-analytics): add access-control checks to taxonomy and joins viewsets (#73009)
Tom Piccirellob2a037d46f0f
diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambrindex 3c9da7b4cb9d..a914f944423e 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends.ambr@@ -107,114 +107,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsUDF.test_timezones_trends[new_events_schema.1]- '''- SELECT fill.entrance_period_start AS entrance_period_start,- countIf(ifNull(notEquals(data.success_bool, 0), 1)) AS reached_from_step_count,- countIf(ifNull(equals(data.success_bool, 1), 0)) AS reached_to_step_count,- if(greater(reached_from_step_count, 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,- data.breakdown AS prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'US/Pacific')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'US/Pacific'), 'US/Pacific') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort') AS data- RIGHT OUTER JOIN- (SELECT plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-04-30 00:00:00'), 6, 'US/Pacific'))), toIntervalDay(period_offsets.number)) AS entrance_period_start- FROM numbers(plus(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-04-30 00:00:00'), 6, 'US/Pacific'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-05-07 23:59:59'), 6, 'US/Pacific')))), 1)) AS period_offsets) AS fill ON equals(data.entrance_period_start, fill.entrance_period_start)- GROUP BY entrance_period_start,- data.breakdown- ORDER BY entrance_period_start ASC- LIMIT 1000 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelTrendsUDF.test_timezones_trends[new_events_schema]- '''- SELECT fill.entrance_period_start AS entrance_period_start,- countIf(ifNull(notEquals(data.success_bool, 0), 1)) AS reached_from_step_count,- countIf(ifNull(equals(data.success_bool, 1), 0)) AS reached_to_step_count,- if(greater(reached_from_step_count, 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,- data.breakdown AS prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort') AS data- RIGHT OUTER JOIN- (SELECT plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-04-30 00:00:00'), 6, 'UTC'))), toIntervalDay(period_offsets.number)) AS entrance_period_start- FROM numbers(plus(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-04-30 00:00:00'), 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-05-07 23:59:59'), 6, 'UTC')))), 1)) AS period_offsets) AS fill ON equals(data.entrance_period_start, fill.entrance_period_start)- GROUP BY entrance_period_start,- data.breakdown- ORDER BY entrance_period_start ASC- LIMIT 1000 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelTrendsUDF.test_week_interval'''SELECT fill.entrance_period_start AS entrance_period_start,@@ -322,110 +214,3 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsUDF.test_week_interval[new_events_schema.1]- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfWeek(timestamp, 0), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 604800, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelTrendsUDF.test_week_interval[new_events_schema]- '''- SELECT fill.entrance_period_start AS entrance_period_start,- countIf(ifNull(notEquals(data.success_bool, 0), 1)) AS reached_from_step_count,- countIf(ifNull(equals(data.success_bool, 1), 0)) AS reached_to_step_count,- if(greater(reached_from_step_count, 0), round(multiply(divide(reached_to_step_count, reached_from_step_count), 100), 2), 0) AS conversion_rate,- data.breakdown AS prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfWeek(timestamp, 0), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 604800, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort') AS data- RIGHT OUTER JOIN- (SELECT plus(toStartOfWeek(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-05-01 00:00:00'), 6, 'UTC')), 0), toIntervalWeek(period_offsets.number)) AS entrance_period_start- FROM numbers(plus(dateDiff('week', toStartOfWeek(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-05-01 00:00:00'), 6, 'UTC')), 0), toStartOfWeek(assumeNotNull(parseDateTime64BestEffortOrNull(('2021-05-07 23:59:59'), 6, 'UTC')), 0)), 1)) AS period_offsets) AS fill ON equals(data.entrance_period_start, fill.entrance_period_start)- GROUP BY entrance_period_start,- data.breakdown- ORDER BY entrance_period_start ASC- LIMIT 1000 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambrindex ebf9a314476b..891f81ec750f 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_actors.ambr@@ -164,171 +164,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_filters_by_breakdown[new_events_schema.1]- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array(['Safari']))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_filters_by_breakdown[new_events_schema.2]- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_filters_by_breakdown[new_events_schema]- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array(['Chrome']))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelTrendsActors.test_funnel_trend_persons_returns_recording_when_converting_step_has_no_session_id'''SELECT source.id,@@ -414,67 +249,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_returns_recording_when_converting_step_has_no_session_id[new_events_schema]- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (SELECT aggregation_target AS actor_id,- matching_events AS matching_events,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 2, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`, arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)]))) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayFilter(e -> and(notEquals(e.3, ''), greater(length(e.5), 0), lessOrEquals(e.1, (user_events_map[af_tuple.4]).1)), arraySort(e -> e.1, user_events)) AS session_events,- [if(greater(length(session_events), 0), session_events[-1], user_events_map[af_tuple.4])] AS matching_events,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelTrendsActors.test_funnel_trend_persons_returns_recordings'''SELECT source.id,@@ -560,67 +334,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_returns_recordings[new_events_schema]- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (SELECT aggregation_target AS actor_id,- matching_events AS matching_events,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 2, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`, arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)]))) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayFilter(e -> and(notEquals(e.3, ''), greater(length(e.5), 0), lessOrEquals(e.1, (user_events_map[af_tuple.4]).1)), arraySort(e -> e.1, user_events)) AS session_events,- [if(greater(length(session_events), 0), session_events[-1], user_events_map[af_tuple.4])] AS matching_events,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelTrendsActors.test_funnel_trend_persons_with_drop_off'''SELECT source.id,@@ -706,67 +419,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_with_drop_off[new_events_schema]- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (SELECT aggregation_target AS actor_id,- matching_events AS matching_events,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`, arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)]))) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayFilter(e -> and(notEquals(e.3, ''), greater(length(e.5), 0), lessOrEquals(e.1, (user_events_map[af_tuple.4]).1)), arraySort(e -> e.1, user_events)) AS session_events,- [if(greater(length(session_events), 0), session_events[-1], user_events_map[af_tuple.4])] AS matching_events,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(notEquals(success_bool, 1), 1), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelTrendsActors.test_funnel_trend_persons_with_no_to_step'''SELECT source.id,@@ -852,64 +504,3 @@use_hive_partitioning=0'''# ----# name: TestFunnelTrendsActors.test_funnel_trend_persons_with_no_to_step[new_events_schema]- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (SELECT aggregation_target AS actor_id,- matching_events AS matching_events,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), toUInt64(toDateTime(toStartOfDay(timestamp), 'UTC')), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel_trends(1, 3, 3, 1209600, 'first_touch', 'ordered', prop, events_array)) AS af_tuple,- toTimeZone(toDateTime(toUInt64(af_tuple.1), 'UTC'), 'UTC') AS entrance_period_start,- af_tuple.2 AS success_bool,- af_tuple.3 AS breakdown,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`, arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)]))) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayFilter(e -> and(notEquals(e.3, ''), greater(length(e.5), 0), lessOrEquals(e.1, (user_events_map[af_tuple.4]).1)), arraySort(e -> e.1, user_events)) AS session_events,- [if(greater(length(session_events), 0), session_events[-1], user_events_map[af_tuple.4])] AS matching_events,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target SETTINGS date_time_output_format='iso',- date_time_input_format='best_effort')- WHERE and(ifNull(equals(success_bool, 1), 0), ifNull(equals(entrance_period_start, toDateTime64('today', 6, 'UTC')), 0))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambrindex 2658837be0fa..b16027a7ca73 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered.ambr@@ -78,385 +78,27 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.1- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.2- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.3- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.4- '''- SELECT source.id,- source.id AS id+ sum(step_3) AS step_3,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,+ groupArray(row_number) AS row_number,+ final_prop AS final_propFROM- (SELECT aggregation_target AS actor_id,- actor_id AS id+ (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,+ groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,+ groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,+ rowNumberInAllBlocks() AS row_number,+ if(less(row_number, 25), breakdown, 'Other') AS final_propFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,@@ -499,18 +141,21 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',+ GROUP BY breakdown+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC)+ GROUP BY final_prop+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC+ LIMIT 26 SETTINGS 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,+ max_bytes_before_external_group_by=23622320128,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,@@ -519,7 +164,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group[new_events_schema.1]+# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.1'''SELECT source.id,source.id AS id@@ -549,7 +194,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -588,7 +233,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group[new_events_schema.2]+# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.2'''SELECT source.id,source.id AS id@@ -618,7 +263,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -657,7 +302,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group[new_events_schema.3]+# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.3'''SELECT source.id,source.id AS id@@ -687,7 +332,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -726,7 +371,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group[new_events_schema.4]+# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group.4'''SELECT source.id,source.id AS id@@ -756,7 +401,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -795,92 +440,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedGroupBreakdown.test_funnel_breakdown_group[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'unordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen'''SELECT sum(step_1) AS step_1,@@ -949,74 +508,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'unordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(and(equals(e.event, 'buy'), ifNull(equals(if(notEquals(toJSONString(e.properties.^`$version`), '{}'), toJSONString(e.properties.^`$version`), if(isNull(e.properties.`$version`), NULL, if(startsWith(dynamicType(e.properties.`$version`), 'DateTime'), replaceOne(toString(e.properties.`$version`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$version`), 'Array'), startsWith(dynamicType(e.properties.`$version`), 'Map'), startsWith(dynamicType(e.properties.`$version`), 'Tuple')), toJSONString(e.properties.`$version`), toString(e.properties.`$version`))))), 'xyz'), 0)), 1, 0) AS step_1,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelUnorderedStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot'''SELECT sum(step_1) AS step_1,@@ -1085,71 +576,3 @@use_hive_partitioning=0'''# ----# name: TestFunnelUnorderedStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'unordered', [if(empty(prop), ['', ''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'buy'), 1, 0) AS step_1,- [ifNull(toString(e.properties.`$browser`), ''), ifNull(toString(if(notEquals(toJSONString(e.properties.^`$version`), '{}'), toJSONString(e.properties.^`$version`), if(isNull(e.properties.`$version`), NULL, if(startsWith(dynamicType(e.properties.`$version`), 'DateTime'), replaceOne(toString(e.properties.`$version`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$version`), 'Array'), startsWith(dynamicType(e.properties.`$version`), 'Map'), startsWith(dynamicType(e.properties.`$version`), 'Tuple')), toJSONString(e.properties.`$version`), toString(e.properties.`$version`)))))), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS 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=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/lifecycle/test/__snapshots__/test_lifecycle_query_runner.ambr b/posthog/hogql_queries/insights/lifecycle/test/__snapshots__/test_lifecycle_query_runner.ambrindex 2bd6057cf8ae..7aa1186d5332 100644--- a/posthog/hogql_queries/insights/lifecycle/test/__snapshots__/test_lifecycle_query_runner.ambr+++ b/posthog/hogql_queries/insights/lifecycle/test/__snapshots__/test_lifecycle_query_runner.ambr@@ -92,89 +92,6 @@use_hive_partitioning=0'''# ----# name: TestLifecycleQueryRunner.test_cohort_filter[new_events_schema]- '''- SELECT groupArray(start_of_period) AS date,- groupArray(counts) AS total,- status AS status- FROM- (SELECT if(ifNull(equals(status, 'dormant'), 0), negate(sum(counts)), negate(negate(sum(counts)))) AS counts,- start_of_period AS start_of_period,- status AS status- FROM- (SELECT periods.start_of_period AS start_of_period,- 0 AS counts,- sec.status AS status- FROM- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS start_of_period- FROM numbers(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(plus(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1)))) AS numbers) AS periods- CROSS JOIN- (SELECT status- FROM- (SELECT 1) ARRAY- JOIN ['new', 'returning', 'resurrecting', 'dormant'] AS status) AS sec- ORDER BY sec.status ASC,- start_of_period ASC- UNION ALL SELECT start_of_period AS start_of_period,- count(DISTINCT actor_id) AS counts,- status AS status- FROM- (SELECT min(events__person.created_at) AS created_at,- arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'UTC'), toIntervalDay(1)))) AS all_activity,- arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity,- arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'UTC'), toIntervalDay(1)))) AS following_activity,- arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status,- arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'UTC'), toIntervalDay(1)), toTimeZone(next, 'UTC')), '', 'dormant'), all_activity, following_activity) AS dormant_status,- arrayMap(x -> plus(toTimeZone(x, 'UTC'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods,- arrayMap(x -> 'dormant', dormant_periods) AS dormant_label,- arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat,- arrayJoin(temp_concat) AS period_status_pairs,- period_status_pairs.1 AS start_of_period,- period_status_pairs.2 AS status,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), in(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))), equals(events.event, '$pageview'))- GROUP BY actor_id)- GROUP BY start_of_period,- status)- WHERE and(lessOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1))), greaterOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))))- GROUP BY start_of_period,- status- ORDER BY start_of_period ASC)- GROUP BY status- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestLifecycleQueryRunner.test_sampling'''SELECT groupArray(start_of_period) AS date,@@ -255,86 +172,6 @@use_hive_partitioning=0'''# ----# name: TestLifecycleQueryRunner.test_sampling[new_events_schema]- '''- SELECT groupArray(start_of_period) AS date,- groupArray(round(multiply(counts, divide(1, 0.1)))) AS total,- status AS status- FROM- (SELECT if(ifNull(equals(status, 'dormant'), 0), negate(sum(counts)), negate(negate(sum(counts)))) AS counts,- start_of_period AS start_of_period,- status AS status- FROM- (SELECT periods.start_of_period AS start_of_period,- 0 AS counts,- sec.status AS status- FROM- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS start_of_period- FROM numbers(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(plus(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1)))) AS numbers) AS periods- CROSS JOIN- (SELECT status- FROM- (SELECT 1) ARRAY- JOIN ['new', 'returning', 'resurrecting', 'dormant'] AS status) AS sec- ORDER BY sec.status ASC,- start_of_period ASC- UNION ALL SELECT start_of_period AS start_of_period,- count(DISTINCT actor_id) AS counts,- status AS status- FROM- (SELECT min(events__person.created_at) AS created_at,- arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'UTC'), toIntervalDay(1)))) AS all_activity,- arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity,- arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'UTC'), toIntervalDay(1)))) AS following_activity,- arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status,- arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'UTC'), toIntervalDay(1)), toTimeZone(next, 'UTC')), '', 'dormant'), all_activity, following_activity) AS dormant_status,- arrayMap(x -> plus(toTimeZone(x, 'UTC'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods,- arrayMap(x -> 'dormant', dormant_periods) AS dormant_label,- arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat,- arrayJoin(temp_concat) AS period_status_pairs,- period_status_pairs.1 AS start_of_period,- period_status_pairs.2 AS status,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events SAMPLE 0.1- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), equals(events.event, '$pageview'))- GROUP BY actor_id)- GROUP BY start_of_period,- status)- WHERE and(lessOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1))), greaterOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))))- GROUP BY start_of_period,- status- ORDER BY start_of_period ASC)- GROUP BY status- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestLifecycleQueryRunner.test_timezones'''SELECT groupArray(start_of_period) AS date,@@ -495,163 +332,3 @@use_hive_partitioning=0'''# ----# name: TestLifecycleQueryRunner.test_timezones[new_events_schema.1]- '''- SELECT groupArray(start_of_period) AS date,- groupArray(counts) AS total,- status AS status- FROM- (SELECT if(ifNull(equals(status, 'dormant'), 0), negate(sum(counts)), negate(negate(sum(counts)))) AS counts,- start_of_period AS start_of_period,- status AS status- FROM- (SELECT periods.start_of_period AS start_of_period,- 0 AS counts,- sec.status AS status- FROM- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS start_of_period- FROM numbers(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'US/Pacific')), toIntervalDay(1)), toStartOfInterval(plus(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1)))) AS numbers) AS periods- CROSS JOIN- (SELECT status- FROM- (SELECT 1) ARRAY- JOIN ['new', 'returning', 'resurrecting', 'dormant'] AS status) AS sec- ORDER BY sec.status ASC,- start_of_period ASC- UNION ALL SELECT start_of_period AS start_of_period,- count(DISTINCT actor_id) AS counts,- status AS status- FROM- (SELECT min(events__person.created_at) AS created_at,- arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'US/Pacific'), toIntervalDay(1)))) AS all_activity,- arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity,- arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'US/Pacific'), toIntervalDay(1)))) AS following_activity,- arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status,- arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), toTimeZone(next, 'US/Pacific')), '', 'dormant'), all_activity, following_activity) AS dormant_status,- arrayMap(x -> plus(toTimeZone(x, 'US/Pacific'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods,- arrayMap(x -> 'dormant', dormant_periods) AS dormant_label,- arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat,- arrayJoin(temp_concat) AS period_status_pairs,- period_status_pairs.1 AS start_of_period,- period_status_pairs.2 AS status,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), equals(events.event, '$pageview'))- GROUP BY actor_id)- GROUP BY start_of_period,- status)- WHERE and(lessOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1))), greaterOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'US/Pacific')), toIntervalDay(1))))- GROUP BY start_of_period,- status- ORDER BY start_of_period ASC)- GROUP BY status- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestLifecycleQueryRunner.test_timezones[new_events_schema]- '''- SELECT groupArray(start_of_period) AS date,- groupArray(counts) AS total,- status AS status- FROM- (SELECT if(ifNull(equals(status, 'dormant'), 0), negate(sum(counts)), negate(negate(sum(counts)))) AS counts,- start_of_period AS start_of_period,- status AS status- FROM- (SELECT periods.start_of_period AS start_of_period,- 0 AS counts,- sec.status AS status- FROM- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS start_of_period- FROM numbers(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(plus(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1)))) AS numbers) AS periods- CROSS JOIN- (SELECT status- FROM- (SELECT 1) ARRAY- JOIN ['new', 'returning', 'resurrecting', 'dormant'] AS status) AS sec- ORDER BY sec.status ASC,- start_of_period ASC- UNION ALL SELECT start_of_period AS start_of_period,- count(DISTINCT actor_id) AS counts,- status AS status- FROM- (SELECT min(events__person.created_at) AS created_at,- arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'UTC'), toIntervalDay(1)))) AS all_activity,- arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity,- arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'UTC'), toIntervalDay(1)))) AS following_activity,- arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'UTC'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status,- arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'UTC'), toIntervalDay(1)), toTimeZone(next, 'UTC')), '', 'dormant'), all_activity, following_activity) AS dormant_status,- arrayMap(x -> plus(toTimeZone(x, 'UTC'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods,- arrayMap(x -> 'dormant', dormant_periods) AS dormant_label,- arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat,- arrayJoin(temp_concat) AS period_status_pairs,- period_status_pairs.1 AS start_of_period,- period_status_pairs.2 AS status,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(1))), equals(events.event, '$pageview'))- GROUP BY actor_id)- GROUP BY start_of_period,- status)- WHERE and(lessOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1))), greaterOrEquals(start_of_period, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))))- GROUP BY start_of_period,- status- ORDER BY start_of_period ASC)- GROUP BY status- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_data_warehouse.ambr b/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_data_warehouse.ambrindex 445dcd9ad29f..4326c44400f7 100644--- a/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_data_warehouse.ambr+++ b/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_data_warehouse.ambr@@ -51,58 +51,6 @@use_hive_partitioning=0'''# ----# name: TestRetentionDataWarehouse.test_retention_data_warehouse_and_events[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT retention_events.actor_id AS actor_id,- arrayFlatten(groupArray(retention_events.start_event_timestamps)) AS start_event_timestamps,- arrayFlatten(groupArray(retention_events.return_event_timestamps)) AS return_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2025-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 4), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM- (SELECT posthog_test_warehouse_event_mix_signups.person_id AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(posthog_test_warehouse_event_mix_signups.signed_up_at, 'UTC')), and(greaterOrEquals(toTimeZone(posthog_test_warehouse_event_mix_signups.signed_up_at, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2025-01-01 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(posthog_test_warehouse_event_mix_signups.signed_up_at, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS start_event_timestamps,- [] AS return_event_timestamps- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.retention.data_warehouse/posthog_test_warehouse_event_mix_signups/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `person_id` UUID, `signed_up_at` DateTime64(3, \'UTC\')') AS posthog_test_warehouse_event_mix_signups- GROUP BY actor_id- UNION ALL SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- [] AS start_event_timestamps,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'paid'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2025-01-01 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2025-01-01 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('paid', 'posthog_test_warehouse_event_mix_signups')), or(equals(events.event, 'posthog_test_warehouse_event_mix_signups'), equals(events.event, 'paid')))- GROUP BY actor_id) AS retention_events- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS format_csv_allow_double_quotes=1,- readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestRetentionDataWarehouse.test_retention_data_warehouse_breakdown_by_warehouse_column'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,diff --git a/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_query_runner.ambr b/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_query_runner.ambrindex 83828c6a02b9..d42d3773291b 100644--- a/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_query_runner.ambr+++ b/posthog/hogql_queries/insights/retention/test/__snapshots__/test_retention_query_runner.ambr@@ -113,120 +113,6 @@use_hive_partitioning=0'''# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating[new_events_schema.1]- '''- SELECT source.key AS key,- source.appearances AS appearances- FROM- (SELECT actor_activity.actor_id AS actor_id,- groupArray(actor_activity.intervals_from_base) AS appearance_intervals,- arraySort(appearance_intervals) AS appearances,- arrayExists(x -> ifNull(equals(x, 0), 0), appearance_intervals) AS week_0,- arrayExists(x -> ifNull(equals(x, 1), 0), appearance_intervals) AS week_1,- arrayExists(x -> ifNull(equals(x, 2), 0), appearance_intervals) AS week_2,- arrayExists(x -> ifNull(equals(x, 3), 0), appearance_intervals) AS week_3,- arrayExists(x -> ifNull(equals(x, 4), 0), appearance_intervals) AS week_4,- arrayExists(x -> ifNull(equals(x, 5), 0), appearance_intervals) AS week_5,- arrayExists(x -> ifNull(equals(x, 6), 0), appearance_intervals) AS week_6,- actor_activity.actor_id AS key- FROM- (SELECT events.`$group_0` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_0`)))- GROUP BY actor_id- HAVING equals(start_interval_index, 0)) AS actor_activity- GROUP BY actor_activity.actor_id) AS source- ORDER BY length(source.appearances) DESC, source.actor_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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating[new_events_schema.2]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.`$group_1` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_1`)))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.`$group_0` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_0`)))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating_person_on_events'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,@@ -341,120 +227,6 @@use_hive_partitioning=0'''# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating_person_on_events[new_events_schema.1]- '''- SELECT source.key AS key,- source.appearances AS appearances- FROM- (SELECT actor_activity.actor_id AS actor_id,- groupArray(actor_activity.intervals_from_base) AS appearance_intervals,- arraySort(appearance_intervals) AS appearances,- arrayExists(x -> ifNull(equals(x, 0), 0), appearance_intervals) AS week_0,- arrayExists(x -> ifNull(equals(x, 1), 0), appearance_intervals) AS week_1,- arrayExists(x -> ifNull(equals(x, 2), 0), appearance_intervals) AS week_2,- arrayExists(x -> ifNull(equals(x, 3), 0), appearance_intervals) AS week_3,- arrayExists(x -> ifNull(equals(x, 4), 0), appearance_intervals) AS week_4,- arrayExists(x -> ifNull(equals(x, 5), 0), appearance_intervals) AS week_5,- arrayExists(x -> ifNull(equals(x, 6), 0), appearance_intervals) AS week_6,- actor_activity.actor_id AS key- FROM- (SELECT events.`$group_0` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_0`)))- GROUP BY actor_id- HAVING equals(start_interval_index, 0)) AS actor_activity- GROUP BY actor_activity.actor_id) AS source- ORDER BY length(source.appearances) DESC, source.actor_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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating_person_on_events[new_events_schema.2]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.`$group_1` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_1`)))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseRetentionGroupAggregation.test_groups_aggregating_person_on_events[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.`$group_0` AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('2020-07-26 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), not(has([''], events.`$group_0`)))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,@@ -641,16 +413,19 @@use_hive_partitioning=0'''# ----# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation[new_events_schema.1]+# name: TestRetention.test_day_interval_sampled'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM- (SELECT actors_with_t0.actor_id AS actor_id,- floor(divide(dateDiff('hour', assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), actors_with_t0.t_0), 24)) AS start_interval_index,- arrayJoin(arrayDistinct(arrayConcat([0], arrayFilter(x -> ifNull(greaterOrEquals(x, 0), 0), groupUniqArray(if(equals(events.event, '$pageview'), floor(divide(dateDiff('hour', actors_with_t0.t_0, toTimeZone(events.timestamp, 'UTC')), 24)), -1)))))) AS intervals_from_base- FROM events_json AS events+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,+ arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,+ arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -658,23 +433,9 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- INNER JOIN- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$pageview')) AS t_0- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING isNotNull(t_0)) AS actors_with_t0 ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), actors_with_t0.actor_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), greaterOrEquals(events.timestamp, actors_with_t0.t_0))- GROUP BY actors_with_t0.actor_id,- actors_with_t0.t_0) AS actor_activity+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))+ GROUP BY actor_id+ HAVING 1) AS actor_activityGROUP BY start_event_matching_interval,intervals_from_baseORDER BY start_event_matching_interval ASC,@@ -693,7 +454,7 @@use_hive_partitioning=0'''# ----# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation[new_events_schema.2]+# name: TestRetention.test_day_interval_sampled.1'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,@@ -704,8 +465,8 @@arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 3), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events+ arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -734,264 +495,7 @@use_hive_partitioning=0'''# ----# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation[new_events_schema.3]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT actors_with_t0.actor_id AS actor_id,- floor(divide(dateDiff('hour', assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), actors_with_t0.t_0), 24)) AS start_interval_index,- arrayJoin(arrayDistinct(arrayConcat([0], arrayFilter(x -> ifNull(greaterOrEquals(x, 0), 0), groupUniqArray(if(equals(events.event, '$pageview'), floor(divide(dateDiff('hour', actors_with_t0.t_0, toTimeZone(events.timestamp, 'UTC')), 24)), -1)))))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- INNER JOIN- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$pageview')) AS t_0- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING isNotNull(t_0)) AS actors_with_t0 ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), actors_with_t0.actor_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')), greaterOrEquals(events.timestamp, actors_with_t0.t_0))- GROUP BY actors_with_t0.actor_id,- actors_with_t0.t_0) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 3), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_day_interval_sampled- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_day_interval_sampled.1- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_day_interval_sampled[new_events_schema.1]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_day_interval_sampled[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_month_interval_with_person_on_events_v2+# name: TestRetention.test_month_interval_with_person_on_events_v2'''SELECT DISTINCT person_id@@ -1041,499 +545,31 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_month_interval_with_person_on_events_v2[new_events_schema.1]+# name: TestRetention.test_retention_aggregation_different_events_ignores_start_event_property_value'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfMonth(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfMonth(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 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('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_month_interval_with_person_on_events_v2[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfMonth(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfMonth(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-01-01 00:00:00', 'UTC')), toIntervalMonth(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_aggregation_different_events_ignores_start_event_property_value- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count,- sum(actor_activity.retention_value) AS aggregation_value- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signed_up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signed_up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'purchased'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,- arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).1 AS intervals_from_base,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).2 AS retention_value- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('purchased', 'signed_up')), or(equals(events.event, 'signed_up'), equals(events.event, 'purchased')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_aggregation_different_events_ignores_start_event_property_value[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count,- sum(actor_activity.retention_value) AS aggregation_value+ count(DISTINCT actor_activity.actor_id) AS count,+ sum(actor_activity.retention_value) AS aggregation_valueFROM(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signed_up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^revenue), '{}'), toJSONString(events.properties.^revenue), if(isNull(events.properties.revenue), NULL, if(startsWith(dynamicType(events.properties.revenue), 'DateTime'), replaceOne(toString(events.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.revenue), 'Array'), startsWith(dynamicType(events.properties.revenue), 'Map'), startsWith(dynamicType(events.properties.revenue), 'Tuple')), toJSONString(events.properties.revenue), toString(events.properties.revenue))))), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signed_up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^revenue), '{}'), toJSONString(events.properties.^revenue), if(isNull(events.properties.revenue), NULL, if(startsWith(dynamicType(events.properties.revenue), 'DateTime'), replaceOne(toString(events.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.revenue), 'Array'), startsWith(dynamicType(events.properties.revenue), 'Map'), startsWith(dynamicType(events.properties.revenue), 'Tuple')), toJSONString(events.properties.revenue), toString(events.properties.revenue))))), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'purchased'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,- arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).1 AS intervals_from_base,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).2 AS retention_value- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('purchased', 'signed_up')), or(equals(events.event, 'signed_up'), equals(events.event, 'purchased')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_aggregation_sum- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count,- sum(actor_activity.retention_value) AS aggregation_value- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,- arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).1 AS intervals_from_base,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).2 AS retention_value- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_aggregation_sum[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count,- sum(actor_activity.retention_value) AS aggregation_value- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^revenue), '{}'), toJSONString(events.properties.^revenue), if(isNull(events.properties.revenue), NULL, if(startsWith(dynamicType(events.properties.revenue), 'DateTime'), replaceOne(toString(events.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.revenue), 'Array'), startsWith(dynamicType(events.properties.revenue), 'Map'), startsWith(dynamicType(events.properties.revenue), 'Tuple')), toJSONString(events.properties.revenue), toString(events.properties.revenue))))), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^revenue), '{}'), toJSONString(events.properties.^revenue), if(isNull(events.properties.revenue), NULL, if(startsWith(dynamicType(events.properties.revenue), 'DateTime'), replaceOne(toString(events.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.revenue), 'Array'), startsWith(dynamicType(events.properties.revenue), 'Map'), startsWith(dynamicType(events.properties.revenue), 'Tuple')), toJSONString(events.properties.revenue), toString(events.properties.revenue))))), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,- arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).1 AS intervals_from_base,- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).2 AS retention_value- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_event_action- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'sign up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$some_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$some_event', 'sign up')), or(equals(events.event, 'sign up'), equals(events.event, '$some_event')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_event_action[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'sign up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$some_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$some_event', 'sign up')), or(equals(events.event, 'sign up'), equals(events.event, '$some_event')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.person_id AS actor_id,- if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(minIf(events.timestamp, equals(events.matches_start, 1)), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.is_return, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])- and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])- and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- 1 AS is_start,- 1 AS matches_start,- 0 AS is_return- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('target_event')), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))- UNION ALL SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- 0 AS is_start,- 0 AS matches_start,- 1 AS is_return- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event')), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(events.event, 'returning_event'))) AS events- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.1- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- if(and(greaterOrEquals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toIntervalDay(1))], []) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'returning_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])- and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])- and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event', 'target_event')), or(and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)), equals(events.event, 'returning_event')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.2- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT events.person_id AS actor_id,- if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(if(equals(minIf(events.timestamp, equals(events.is_start, 1)), minIf(events.timestamp, equals(events.matches_start, 1))), minIf(events.timestamp, equals(events.is_start, 1)), NULL), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.is_return, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])- and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])- and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- 1 AS is_start,- and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)) AS matches_start,- 0 AS is_return- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('target_event')), equals(events.event, 'target_event'))- UNION ALL SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- 0 AS is_start,- 0 AS matches_start,- 1 AS is_return- FROM events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event')), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(events.event, 'returning_event'))) AS events+ groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signed_up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,+ groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'purchased'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,+ arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,+ arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,+ arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).1 AS intervals_from_base,+ arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), 0.0), _start_event_data)), arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 8), item.1), 1), 'Int64'), item.2), arrayFilter(x -> or(greater(x.1, date_range[plus(start_interval_index, 1)]), and(equals(x.1, date_range[plus(start_interval_index, 1)]), greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> equals(z.1, date_range[plus(start_interval_index, 1)]), _start_event_data)))))), _return_event_data))))).2 AS retention_value+ FROM events+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('purchased', 'signed_up')), or(equals(events.event, 'signed_up'), equals(events.event, 'purchased')))GROUP BY actor_idHAVING 1) AS actor_activityGROUP BY start_event_matching_interval,@@ -1554,20 +590,22 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.3+# name: TestRetention.test_retention_aggregation_sum'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count+ count(DISTINCT actor_activity.actor_id) AS count,+ sum(actor_activity.retention_value) AS aggregation_valueFROM(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- if(and(greaterOrEquals(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toIntervalDay(1))], []) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'returning_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])- and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])- and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,+ groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _start_event_data,+ groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), ifNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64'), 0.0), toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))))) AS _return_event_data,+ arrayMap(x -> x.1, _return_event_data) AS return_event_timestamps,+ arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,+ arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).1 AS intervals_from_base,+ arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(equals(item.1, date_range[plus(start_interval_index, 1)]), 0, -1), 'Int64'), item.2), _start_event_data)), arrayFilter(x -> ifNull(greater(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(indexOf(arraySlice(date_range, plus(start_interval_index, 2), 7), item.1), 'Int64'), item.2), _return_event_data)))).2 AS retention_valueFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -1576,7 +614,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event', 'target_event')))+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))GROUP BY actor_idHAVING 1) AS actor_activityGROUP BY start_event_matching_interval,@@ -1597,21 +635,19 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence[new_events_schema.1]+# name: TestRetention.test_retention_event_action'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- if(and(greaterOrEquals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0))), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0))), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0))), toIntervalDay(1))], []) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'returning_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])- and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])- and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'sign up'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$some_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,+ arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,+ arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1619,7 +655,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event', 'target_event')), or(and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)), equals(events.event, 'returning_event')))+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$some_event', 'sign up')), or(equals(events.event, 'sign up'), equals(events.event, '$some_event')))GROUP BY actor_idHAVING 1) AS actor_activityGROUP BY start_event_matching_interval,@@ -1640,14 +676,14 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence[new_events_schema.2]+# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM(SELECT events.person_id AS actor_id,- if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(if(equals(minIf(events.timestamp, equals(events.is_start, 1)), minIf(events.timestamp, equals(events.matches_start, 1))), minIf(events.timestamp, equals(events.is_start, 1)), NULL), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,+ if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(minIf(events.timestamp, equals(events.matches_start, 1)), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.is_return, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])@@ -1658,9 +694,9 @@(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,toTimeZone(events.timestamp, 'UTC') AS timestamp,1 AS is_start,- and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)) AS matches_start,+ 1 AS matches_start,0 AS is_return- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1668,13 +704,13 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('target_event')), equals(events.event, 'target_event'))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('target_event')), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))UNION ALL SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,toTimeZone(events.timestamp, 'UTC') AS timestamp,0 AS is_start,0 AS matches_start,1 AS is_return- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1703,21 +739,21 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence[new_events_schema.3]+# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.1'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- if(and(greaterOrEquals(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toIntervalDay(1))], []) AS start_event_timestamps,+ if(and(greaterOrEquals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0))), toIntervalDay(1))], []) AS start_event_timestamps,arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'returning_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1725,7 +761,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('returning_event', 'target_event')))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('returning_event', 'target_event')), or(and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)), equals(events.event, 'returning_event')))GROUP BY actor_idHAVING 1) AS actor_activityGROUP BY start_event_matching_interval,@@ -1746,14 +782,14 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence[new_events_schema]+# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.2'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM(SELECT events.person_id AS actor_id,- if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(minIf(events.timestamp, equals(events.matches_start, 1)), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,+ if(has(arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.matches_start, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS _start_event_timestamps, toStartOfInterval(if(equals(minIf(events.timestamp, equals(events.is_start, 1)), minIf(events.timestamp, equals(events.matches_start, 1))), minIf(events.timestamp, equals(events.is_start, 1)), NULL), toIntervalDay(1))), _start_event_timestamps, []) AS start_event_timestamps,arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,arraySort(groupUniqArrayIf(toStartOfDay(events.timestamp), and(equals(events.is_return, 1), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])@@ -1764,9 +800,9 @@(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,toTimeZone(events.timestamp, 'UTC') AS timestamp,1 AS is_start,- 1 AS matches_start,+ and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)) AS matches_start,0 AS is_return- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1774,13 +810,13 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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), in(events.event, tuple('target_event')), and(equals(events.event, 'target_event'), ifNull(equals(if(notEquals(toJSONString(events.properties.^prop), '{}'), toJSONString(events.properties.^prop), if(isNull(events.properties.prop), NULL, if(startsWith(dynamicType(events.properties.prop), 'DateTime'), replaceOne(toString(events.properties.prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.prop), 'Array'), startsWith(dynamicType(events.properties.prop), 'Map'), startsWith(dynamicType(events.properties.prop), 'Tuple')), toJSONString(events.properties.prop), toString(events.properties.prop))))), 'correct'), 0)))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('target_event')), equals(events.event, 'target_event'))UNION ALL SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,toTimeZone(events.timestamp, 'UTC') AS timestamp,0 AS is_start,0 AS matches_start,1 AS is_return- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1809,18 +845,20 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_with_user_properties_via_action+# name: TestRetention.test_retention_first_time_vs_first_ever_occurrence.3'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,count(DISTINCT actor_activity.actor_id) AS countFROM(SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(or(and(equals(events.event, '$pageview'), ifNull(equals(events__person.properties___email, '[email protected]'), 0)), equals(events.event, 'non_matching_event')), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base+ if(and(greaterOrEquals(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'target_event'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'prop'), ''), 'null'), '^"|"$', ''), 'correct'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'target_event')), NULL), toIntervalDay(1))], []) AS start_event_timestamps,+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 6)) AS date_range,+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'returning_event'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,+ arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(ifNull(equals(_start_event_timestamps[1], interval_date), isNull(_start_event_timestamps[1])+ and isNull(interval_date)), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,+ arrayJoin(arrayConcat(if(ifNull(equals(start_event_timestamps[1], date_range[plus(start_interval_index, 1)]), isNull(start_event_timestamps[1])+ and isNull(date_range[plus(start_interval_index, 1)])), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 5), _timestamp), 1), return_event_timestamps)))) AS intervals_from_baseFROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -1829,17 +867,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview', 'non_matching_event')), or(or(and(equals(events.event, '$pageview'), ifNull(equals(events__person.properties___email, '[email protected]'), 0)), equals(events.event, 'non_matching_event')), equals(events.event, '$pageview')))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('returning_event', 'target_event')))GROUP BY actor_idHAVING 1) AS actor_activityGROUP BY start_event_matching_interval,@@ -1860,7 +888,7 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_retention_with_user_properties_via_action[new_events_schema]+# name: TestRetention.test_retention_with_user_properties_via_action'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,actor_activity.intervals_from_base AS intervals_from_base,@@ -1872,7 +900,7 @@arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events+ FROM eventsLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -1993,88 +1021,6 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_timezones[new_events_schema.1]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'US/Pacific')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'US/Pacific'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'US/Pacific')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'US/Pacific'), toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'US/Pacific')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'US/Pacific'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'US/Pacific')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'US/Pacific'), toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'US/Pacific')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_timezones[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 11)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestRetention.test_week_interval'''SELECT actor_activity.start_interval_index AS start_event_matching_interval,@@ -2157,85 +1103,3 @@use_hive_partitioning=0'''# ----# name: TestRetention.test_week_interval[new_events_schema.1]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 3), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-08 00:00:00', 'UTC')), 3)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-08 00:00:00', 'UTC')), 3), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 3), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-08 00:00:00', 'UTC')), 3)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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, toStartOfWeek(assumeNotNull(toDateTime('2020-06-08 00:00:00', 'UTC')), 3)), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestRetention.test_week_interval[new_events_schema]- '''- SELECT actor_activity.start_interval_index AS start_event_matching_interval,- actor_activity.intervals_from_base AS intervals_from_base,- count(DISTINCT actor_activity.actor_id) AS count- FROM- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS start_event_timestamps,- arrayMap(x -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0), toIntervalWeek(x)), range(0, 7)) AS date_range,- arraySort(groupUniqArrayIf(toStartOfWeek(toTimeZone(events.timestamp, 'UTC'), 0), and(equals(events.event, '$pageview'), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))) AS return_event_timestamps,- arrayJoin(arrayFilter(x -> ifNull(greater(x, -1), 0), arrayMap((interval_index, interval_date, _start_event_timestamps) -> if(has(_start_event_timestamps, interval_date), minus(interval_index, 1), -1), arrayEnumerate(date_range), date_range, arrayResize([start_event_timestamps], length(date_range), start_event_timestamps)))) AS start_interval_index,- arrayJoin(arrayConcat(if(has(start_event_timestamps, date_range[plus(start_interval_index, 1)]), [0], []), arrayFilter(x -> ifNull(greater(x, 0), 0), arrayMap(_timestamp -> minus(indexOf(arraySlice(date_range, plus(start_interval_index, 1), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 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, toStartOfWeek(assumeNotNull(toDateTime('2020-06-07 00:00:00', 'UTC')), 0)), less(events.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(events.event, tuple('$pageview')), or(equals(events.event, '$pageview'), equals(events.event, '$pageview')))- GROUP BY actor_id- HAVING 1) AS actor_activity- GROUP BY start_event_matching_interval,- intervals_from_base- ORDER BY start_event_matching_interval ASC,- intervals_from_base ASC- LIMIT 100000 SETTINGS readonly=2,- max_execution_time=600,- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambrindex fbc8a4e61e3c..cf656e77a127 100644--- a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr+++ b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr@@ -21,28 +21,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_events_trends_query[new_events_schema]- '''- SELECT distinct_id AS distinct_id- FROM- (SELECT e.distinct_id AS distinct_id- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-12 00:00:00.000000', 6, 'US/Pacific')), less(e.timestamp, toDateTime64('2020-01-13 00:00:00.000000', 6, 'US/Pacific')), equals(e.event, '$pageview')), less(e.timestamp, toDateTime64('today', 6, 'US/Pacific')))- ORDER BY e.distinct_id ASC)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_funnels_query'''SELECT name AS name@@ -107,70 +85,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_funnels_query[new_events_schema]- '''- SELECT name AS name- FROM- (SELECT persons.properties___name AS name- FROM- (SELECT aggregation_target AS actor_id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, '$pageview'), 1, 0) AS step_0,- if(equals(e.event, '$pageview'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('$pageview'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 1)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- INNER JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_lifecycle_query'''SELECT n AS n@@ -261,96 +175,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_lifecycle_query[new_events_schema]- '''- SELECT n AS n- FROM- (SELECT persons.properties___name AS n- FROM- (SELECT DISTINCT actor_id AS actor_id- FROM- (SELECT min(events__person.created_at) AS created_at,- arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'US/Pacific'), toIntervalDay(1)))) AS all_activity,- arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity,- arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'US/Pacific'), toIntervalDay(1)))) AS following_activity,- arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status,- arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), toTimeZone(next, 'US/Pacific')), '', 'dormant'), all_activity, following_activity) AS dormant_status,- arrayMap(x -> plus(toTimeZone(x, 'US/Pacific'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods,- arrayMap(x -> 'dormant', dormant_periods) AS dormant_label,- arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat,- arrayJoin(temp_concat) AS period_status_pairs,- period_status_pairs.1 AS start_of_period,- period_status_pairs.2 AS status,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), equals(events.event, '$pageview'))- GROUP BY actor_id)- WHERE and(equals(start_of_period, toStartOfInterval(toDateTime('2020-01-12', 'US/Pacific'), toIntervalDay(1))), equals(status, 'returning'))) AS source- INNER JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE and(equals(person.team_id, 99999), in(person.id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT DISTINCT actor_id AS actor_id- FROM- (SELECT min(events__person.created_at) AS created_at, arraySort(groupUniqArray(toStartOfInterval(toTimeZone(events.timestamp, 'US/Pacific'), toIntervalDay(1)))) AS all_activity, arrayPopBack(arrayPushFront(all_activity, toStartOfInterval(created_at, toIntervalDay(1)))) AS previous_activity, arrayPopFront(arrayPushBack(all_activity, toStartOfInterval(toDateTime('1970-01-01 00:00:00', 'US/Pacific'), toIntervalDay(1)))) AS following_activity, arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous)- and isNull(current)), 'new', if(and(ifNull(equals(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), previous), isNull(minus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)))- and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status, arrayMap((current, next) -> if(equals(plus(toTimeZone(current, 'US/Pacific'), toIntervalDay(1)), toTimeZone(next, 'US/Pacific')), '', 'dormant'), all_activity, following_activity) AS dormant_status, arrayMap(x -> plus(toTimeZone(x, 'US/Pacific'), toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods, arrayMap(x -> 'dormant', dormant_periods) AS dormant_label, arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat, arrayJoin(temp_concat) AS period_status_pairs, period_status_pairs.1 AS start_of_period, period_status_pairs.2 AS status, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id- FROM events_json AS events- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at, person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(events.properties.`$process_person_profile`, 'false'), 1), greaterOrEquals(events.timestamp, minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), less(events.timestamp, plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(1))), equals(events.event, '$pageview'))- GROUP BY actor_id)- WHERE and(equals(start_of_period, toStartOfInterval(toDateTime('2020-01-12', 'US/Pacific'), toIntervalDay(1))), equals(status, 'returning'))) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_stickiness_groups_query'''SELECT name AS name@@ -395,50 +219,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_stickiness_groups_query[new_events_schema]- '''- SELECT name AS name- FROM- (SELECT groups.properties___name AS name- FROM- (SELECT aggregation_target AS group_key- FROM- (SELECT aggregation_target AS aggregation_target,- count() AS num_intervals- FROM- (SELECT e.`$group_0` AS aggregation_target,- toStartOfInterval(toTimeZone(e.timestamp, 'US/Pacific'), toIntervalDay(1)) AS start_of_interval- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'), notEquals(e.`$group_0`, ''))- GROUP BY aggregation_target,- start_of_interval- HAVING greater(count(), 0))- GROUP BY aggregation_target)- WHERE equals(num_intervals, 7)) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'US/Pacific')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups ON equals(groups.key, source.group_key)- ORDER BY groups.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_stickiness_query'''SELECT name AS name@@ -511,78 +291,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_stickiness_query[new_events_schema]- '''- SELECT name AS name- FROM- (SELECT persons.properties___name AS name- FROM- (SELECT aggregation_target AS actor_id- FROM- (SELECT aggregation_target AS aggregation_target,- count() AS num_intervals- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- toStartOfInterval(toTimeZone(e.timestamp, 'US/Pacific'), toIntervalDay(1)) AS start_of_interval- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'))- GROUP BY aggregation_target,- start_of_interval- HAVING greater(count(), 0))- GROUP BY aggregation_target)- WHERE equals(num_intervals, 2)) AS source- INNER JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE and(equals(person.team_id, 99999), in(person.id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT aggregation_target AS actor_id- FROM- (SELECT aggregation_target AS aggregation_target, count() AS num_intervals- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, toStartOfInterval(toTimeZone(e.timestamp, 'US/Pacific'), toIntervalDay(1)) AS start_of_interval- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'))- GROUP BY aggregation_target, start_of_interval- HAVING greater(count(), 0))- GROUP BY aggregation_target)- WHERE equals(num_intervals, 2)) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_trends_groups_query'''SELECT name AS name@@ -623,46 +331,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_trends_groups_query[new_events_schema]- '''- SELECT name AS name- FROM- (SELECT groups.properties___name AS name- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- max(timestamp) AS last_seen- FROM- (SELECT e.`$group_0` AS actor_id,- toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- e.uuid AS uuid- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('2020-01-09 00:00:00.000000', 6, 'US/Pacific')), less(timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'US/Pacific')), notEquals(e.`$group_0`, ''), equals(e.event, '$pageview')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'US/Pacific')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups ON equals(groups.key, source.actor_id)- ORDER BY groups.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_trends_query_with_argmaxV1'''SELECT name AS name,@@ -740,83 +408,6 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_trends_query_with_argmaxV1[new_events_schema]- '''- SELECT name AS name,- event_distinct_ids AS event_distinct_ids- FROM- (SELECT persons.properties___name AS name,- source.event_distinct_ids AS event_distinct_ids- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- groupUniqArray(distinct_id) AS event_distinct_ids,- max(timestamp) AS last_seen- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- e.uuid AS uuid,- e.distinct_id AS distinct_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___email,- person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), ifNull(notEquals(e__person.properties___email, '[email protected]'), 1), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), less(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), equals(e.event, '$pageview')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___name,- person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, max(timestamp) AS last_seen- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id, toTimeZone(e.timestamp, 'US/Pacific') AS timestamp, e.uuid AS uuid, e.distinct_id AS distinct_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___email, person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), ifNull(notEquals(e__person.properties___email, '[email protected]'), 1), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), less(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), equals(e.event, '$pageview')))- GROUP BY actor_id) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestInsightActorsQueryRunner.test_insight_persons_trends_query_with_argmaxV2'''SELECT name AS name,@@ -903,89 +494,3 @@use_hive_partitioning=0'''# ----# name: TestInsightActorsQueryRunner.test_insight_persons_trends_query_with_argmaxV2[new_events_schema]- '''- SELECT name AS name,- event_distinct_ids AS event_distinct_ids- FROM- (SELECT persons.properties___name AS name,- source.event_distinct_ids AS event_distinct_ids- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- groupUniqArray(distinct_id) AS event_distinct_ids,- max(timestamp) AS last_seen- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- e.uuid AS uuid,- e.distinct_id AS distinct_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), ifNull(notEquals(e__person.properties___email, '[email protected]'), 1), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), less(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), equals(e.event, '$pageview')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE and(equals(person.team_id, 99999), in(person.id,- (SELECT source.actor_id AS actor_id- FROM- (SELECT actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, max(timestamp) AS last_seen- FROM- (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id, toTimeZone(e.timestamp, 'US/Pacific') AS timestamp, e.uuid AS uuid, e.distinct_id AS distinct_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), ifNull(notEquals(e__person.properties___email, '[email protected]'), 1), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), less(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), equals(e.event, '$pageview')))- GROUP BY actor_id) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY persons.properties___name ASC SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto')- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_boxplot_trends_query_runner.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_boxplot_trends_query_runner.ambrindex 711b678864a4..ab5f8c6618c6 100644--- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_boxplot_trends_query_runner.ambr+++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_boxplot_trends_query_runner.ambr@@ -26,824 +26,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_custom_event_name[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^amount), '{}'), toJSONString(e.properties.^amount), if(isNull(e.properties.amount), NULL, if(startsWith(dynamicType(e.properties.amount), 'DateTime'), replaceOne(toString(e.properties.amount), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.amount), 'Array'), startsWith(dynamicType(e.properties.amount), 'Map'), startsWith(dynamicType(e.properties.amount), 'Tuple')), toJSONString(e.properties.amount), toString(e.properties.amount))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), equals(e.event, 'purchase'))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_0_day- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_0_day[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_1_hour- '''- SELECT toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 12:00:00', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_1_hour[new_events_schema]- '''- SELECT toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 12:00:00', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_2_minute- '''- SELECT toStartOfMinute(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalMinute(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 10:05:00', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_2_minute[new_events_schema]- '''- SELECT toStartOfMinute(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalMinute(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 10:05:00', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_3_week- '''- SELECT toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-11-27 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_3_week[new_events_schema]- '''- SELECT toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-11-27 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_4_month- '''- SELECT toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-10-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-31 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_4_month[new_events_schema]- '''- SELECT toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-10-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-31 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_each_datum_has_label_and_day- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_each_datum_has_label_and_day[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_0_filter_test_accounts_off- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_0_filter_test_accounts_off[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_1_filter_test_accounts_on- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_1_filter_test_accounts_on[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_days_produce_separate_buckets_with_correct_stats- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_days_produce_separate_buckets_with_correct_stats[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each.1- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), equals(e.event, 'other_event'))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each[new_events_schema.1]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^other_prop), '{}'), toJSONString(e.properties.^other_prop), if(isNull(e.properties.other_prop), NULL, if(startsWith(dynamicType(e.properties.other_prop), 'DateTime'), replaceOne(toString(e.properties.other_prop), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.other_prop), 'Array'), startsWith(dynamicType(e.properties.other_prop), 'Map'), startsWith(dynamicType(e.properties.other_prop), 'Tuple')), toJSONString(e.properties.other_prop), toString(e.properties.other_prop))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), equals(e.event, 'other_event'))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_users_aggregate_within_same_day- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_multiple_users_aggregate_within_same_day[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_no_data_fills_all_dates_with_zeros- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_no_data_fills_all_dates_with_zeros[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_0_all_missing- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,- max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,- avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_0_all_missing[new_events_schema]- '''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY day_start- ORDER BY day_start ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_1_single_missing+# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_0_day'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -870,17 +53,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_1_single_missing[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_1_hour'''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ SELECT toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 12:00:00', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -897,9 +80,9 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_0_filter_chrome_only+# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_2_minute'''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ SELECT toStartOfMinute(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,@@ -907,7 +90,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Chrome'), 0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 10:00:00', 'UTC')), toIntervalMinute(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 10:05:00', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -924,17 +107,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_0_filter_chrome_only[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_3_week'''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), and(equals(e.properties.`$browser`, 'Chrome'), isNotNull(e.properties.`$browser`)))+ SELECT toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start,+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-11-27 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -951,9 +134,9 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_1_filter_firefox_only+# name: TestBoxPlotTrendsQueryRunner.test_day_format_varies_by_interval_4_month'''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ SELECT toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,@@ -961,7 +144,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Firefox'), 0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-10-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-31 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -978,17 +161,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_1_filter_firefox_only[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_each_datum_has_label_and_day'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), and(equals(e.properties.`$browser`, 'Firefox'), isNotNull(e.properties.`$browser`)))+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1005,7 +188,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_2_no_filter_sees_both+# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_0_filter_test_accounts_off'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1032,17 +215,34 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_property_filters_2_no_filter_sees_both[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_filter_test_accounts_1_filter_test_accounts_on'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1059,7 +259,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_results_are_ordered_by_day_ascending+# name: TestBoxPlotTrendsQueryRunner.test_multiple_days_produce_separate_buckets_with_correct_stats'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1069,7 +269,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-05 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-03 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1086,17 +286,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_results_are_ordered_by_day_ascending[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-05 23:59:59', 'UTC'))))+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1113,28 +313,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_session_duration_produces_boxplot_data+# name: TestBoxPlotTrendsQueryRunner.test_multiple_series_returns_data_for_each.1'''- SELECT day_start AS day_start,- min(accurateCastOrNull(session_duration, 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(session_duration, 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(session_duration, 'Float64')) AS p75,- max(accurateCastOrNull(session_duration, 'Float64')) AS max_val,- avg(accurateCastOrNull(session_duration, 'Float64')) AS mean_val- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- any(e__session.`$session_duration`) AS session_duration- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY e.`$session_id`,- day_start)+ SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'other_prop'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), equals(e.event, 'other_event'))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1151,28 +340,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_session_duration_produces_boxplot_data[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_multiple_users_aggregate_within_same_day'''- SELECT day_start AS day_start,- min(accurateCastOrNull(session_duration, 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(session_duration, 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(session_duration, 'Float64')) AS p75,- max(accurateCastOrNull(session_duration, 'Float64')) AS max_val,- avg(accurateCastOrNull(session_duration, 'Float64')) AS mean_val- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- any(e__session.`$session_duration`) AS session_duration- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))- GROUP BY e.`$session_id`,- day_start)+ SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1189,7 +367,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_sparse_data_fills_missing_dates_with_zeros+# name: TestBoxPlotTrendsQueryRunner.test_no_data_fills_all_dates_with_zeros'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1199,7 +377,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-10 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1216,17 +394,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_sparse_data_fills_missing_dates_with_zeros[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_0_all_missing'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1243,7 +421,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_0_uniform_distribution+# name: TestBoxPlotTrendsQueryRunner.test_none_property_values_become_zero_1_single_missing'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1270,17 +448,17 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_0_uniform_distribution[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_property_filters_0_filter_chrome_only'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Chrome'), 0))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1297,7 +475,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_1_single_value+# name: TestBoxPlotTrendsQueryRunner.test_property_filters_1_filter_firefox_only'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1307,7 +485,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Firefox'), 0))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1324,16 +502,16 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_1_single_value[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_property_filters_2_no_filter_sees_both'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASC@@ -1351,7 +529,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_2_two_values+# name: TestBoxPlotTrendsQueryRunner.test_results_are_ordered_by_day_ascending'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1361,7 +539,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-05 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1378,17 +556,28 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_2_two_values[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_session_duration_produces_boxplot_data'''- SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ SELECT day_start AS day_start,+ min(accurateCastOrNull(session_duration, 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(session_duration, 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(session_duration, 'Float64')) AS p75,+ max(accurateCastOrNull(session_duration, 'Float64')) AS max_val,+ avg(accurateCastOrNull(session_duration, 'Float64')) AS mean_val+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ any(e__session.`$session_duration`) AS session_duration+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ GROUP BY e.`$session_id`,+ day_start)GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1405,7 +594,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_3_identical_values+# name: TestBoxPlotTrendsQueryRunner.test_sparse_data_fills_missing_dates_with_zeros'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1415,7 +604,7 @@max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_valFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-07 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCLIMIT 100 SETTINGS readonly=2,@@ -1432,16 +621,16 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_3_identical_values[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_0_uniform_distribution'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASC@@ -1459,7 +648,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_4_negative_values+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_1_single_value'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1486,16 +675,16 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_4_negative_values[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_2_two_values'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASC@@ -1513,7 +702,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_5_large_values+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_3_identical_values'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1540,16 +729,16 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_5_large_values[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_4_negative_values'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASC@@ -1567,7 +756,7 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_6_decimal_values+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_5_large_values'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,@@ -1594,16 +783,16 @@use_hive_partitioning=0'''# ----# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_6_decimal_values[new_events_schema]+# name: TestBoxPlotTrendsQueryRunner.test_statistics_for_distribution_6_decimal_values'''SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- min(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS min_val,- quantile(0.25)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p25,- quantile(0.5)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS median_val,- quantile(0.75)(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS p75,- max(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS max_val,- avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^revenue), '{}'), toJSONString(e.properties.^revenue), if(isNull(e.properties.revenue), NULL, if(startsWith(dynamicType(e.properties.revenue), 'DateTime'), replaceOne(toString(e.properties.revenue), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.revenue), 'Array'), startsWith(dynamicType(e.properties.revenue), 'Map'), startsWith(dynamicType(e.properties.revenue), 'Tuple')), toJSONString(e.properties.revenue), toString(e.properties.revenue))))), 'Float64')) AS mean_val- FROM events_json AS e+ min(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS min_val,+ quantile(0.25)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p25,+ quantile(0.5)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS median_val,+ quantile(0.75)(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS p75,+ max(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS max_val,+ avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'revenue'), ''), 'null'), '^"|"$', ''), 'Float64')) AS mean_val+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2023-12-02 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2023-12-02 23:59:59', 'UTC'))))GROUP BY day_startORDER BY day_start ASCdiff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_formula.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_formula.ambrindex a9cbb793b3a6..201cefac2dc9 100644--- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_formula.ambr+++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_formula.ambr@@ -39,46 +39,6 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_aggregated_one_without_events[new_events_schema.1]- '''- SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^`session not here`), '{}'), toJSONString(e.properties.^`session not here`), if(isNull(e.properties.`session not here`), NULL, if(startsWith(dynamicType(e.properties.`session not here`), 'DateTime'), replaceOne(toString(e.properties.`session not here`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`session not here`), 'Array'), startsWith(dynamicType(e.properties.`session not here`), 'Map'), startsWith(dynamicType(e.properties.`session not here`), 'Tuple')), toJSONString(e.properties.`session not here`), toString(e.properties.`session not here`))))), 'Float64')), 0) AS total- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session error'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_aggregated_one_without_events[new_events_schema]- '''- SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFormula.test_breakdown'''SELECT groupArray(1)(date)[1] AS date,@@ -171,98 +131,6 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT avg(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFormula.test_breakdown_aggregated'''SELECT sum(total) AS total,@@ -343,86 +211,6 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_aggregated[new_events_schema.1]- '''- SELECT avg(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number- FROM- (SELECT avg(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_aggregated[new_events_schema]- '''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number- FROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFormula.test_breakdown_cohort'''@@ -637,7 +425,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_cohort[new_events_schema.1]+# name: TestFormula.test_breakdown_hogql'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -649,14 +437,31 @@breakdown_value AS breakdown_value,rowNumberInAllBlocks() AS row_numberFROM- (SELECT avg(total) AS count,+ (SELECT sum(total) AS count,day_start AS day_start,breakdown_value AS breakdown_valueFROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- toString(0) AS breakdown_value- FROM events_json AS e+ ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start,breakdown_value)@@ -665,10 +470,10 @@ORDER BY day_start ASC,breakdown_value ASC)GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -683,7 +488,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_cohort[new_events_schema.2]+# name: TestFormula.test_breakdown_hogql.1'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -695,14 +500,14 @@breakdown_value AS breakdown_value,rowNumberInAllBlocks() AS row_numberFROM- (SELECT sum(total) AS count,+ (SELECT avg(total) AS count,day_start AS day_start,breakdown_value AS breakdown_valueFROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,+ (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- toString(999932324) AS breakdown_value- FROM events_json AS e+ ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -710,10 +515,17 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start,breakdown_value)GROUP BY day_start,@@ -721,10 +533,10 @@ORDER BY day_start ASC,breakdown_value ASC)GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -739,7 +551,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_cohort[new_events_schema.3]+# name: TestFormula.test_breakdown_hogql_with_as_alias'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -751,133 +563,14 @@breakdown_value AS breakdown_value,rowNumberInAllBlocks() AS row_numberFROM- (SELECT avg(total) AS count,+ (SELECT sum(total) AS count,day_start AS day_start,breakdown_value AS breakdown_valueFROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- toString(999932324) AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_cohort[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- toString(0) AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_valueFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start,breakdown_value)@@ -904,7 +597,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_hogql.1+# name: TestFormula.test_breakdown_hogql_with_as_alias.1'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -922,151 +615,8 @@FROM(SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_valueFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT avg(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(concat(ifNull(toString(e__person.`properties___$some_prop`), ''), ' : ', ifNull(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), ''))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start,breakdown_value)@@ -1093,7 +643,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_breakdown_hogql_with_as_alias+# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -1101,725 +651,30 @@FROM(SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql_with_as_alias.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT avg(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql_with_as_alias[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT avg(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_hogql_with_as_alias[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^location), '{}'), toJSONString(e.properties.^location), if(isNull(e.properties.location), NULL, if(startsWith(dynamicType(e.properties.location), 'DateTime'), replaceOne(toString(e.properties.location), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.location), 'Array'), startsWith(dynamicType(e.properties.location), 'Map'), startsWith(dynamicType(e.properties.location), 'Tuple')), toJSONString(e.properties.location), toString(e.properties.location)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_hogql_math_no_matching_events- '''- SELECT ifNull(accurateCastOrNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 'Float64'), 0) AS total- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'nonexistent_event_that_has_no_data'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_hogql_math_no_matching_events.1- '''- SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_hogql_math_no_matching_events[new_events_schema.1]- '''- SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_hogql_math_no_matching_events[new_events_schema]- '''- SELECT ifNull(accurateCastOrNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 'Float64'), 0) AS total- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'nonexistent_event_that_has_no_data'))- ORDER BY 1 DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_unique_sessions- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.`$session_id`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_unique_sessions.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_unique_sessions[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_formula_with_unique_sessions[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.`$session_id`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_hour_interval_day_level_relative- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_hour_interval_day_level_relative.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT avg(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_hour_interval_day_level_relative[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT avg(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_hour_interval_day_level_relative[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFormula.test_hour_interval_hour_level_relative- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_number+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1834,23 +689,38 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_hour_interval_hour_level_relative.1+# name: TestFormula.test_breakdown_with_different_breakdown_values_per_series.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT avg(total) AS count,- day_start AS day_start+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'location'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1865,23 +735,12 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_hour_interval_hour_level_relative[new_events_schema.1]+# name: TestFormula.test_formula_with_hogql_math_no_matching_events'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT avg(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ SELECT ifNull(accurateCastOrNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 'Float64'), 0) AS total+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'nonexistent_event_that_has_no_data'))+ ORDER BY 1 DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1896,23 +755,12 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_hour_interval_hour_level_relative[new_events_schema]+# name: TestFormula.test_formula_with_hogql_math_no_matching_events.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(sum(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^xyz), '{}'), toJSONString(e.properties.^xyz), if(isNull(e.properties.xyz), NULL, if(startsWith(dynamicType(e.properties.xyz), 'DateTime'), replaceOne(toString(e.properties.xyz), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.xyz), 'Array'), startsWith(dynamicType(e.properties.xyz), 'Map'), startsWith(dynamicType(e.properties.xyz), 'Tuple')), toJSONString(e.properties.xyz), toString(e.properties.xyz))))), 'Float64')), 0) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))+ ORDER BY 1 DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1927,31 +775,19 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_session_duration_aggregation+# name: TestFormula.test_formula_with_unique_sessions'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT avg(total) AS count,+ (SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(avg(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- e.`$session_id`,- day_start)+ (SELECT count(DISTINCT e.`$session_id`) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -1970,7 +806,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_session_duration_aggregation.1+# name: TestFormula.test_formula_with_unique_sessions.1'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -1979,10 +815,17 @@(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2001,19 +844,19 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_session_duration_aggregation[new_events_schema.1]+# name: TestFormula.test_hour_interval_day_level_relative'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2032,31 +875,19 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_session_duration_aggregation[new_events_schema]+# name: TestFormula.test_hour_interval_day_level_relative.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT avg(total) AS count,day_start AS day_startFROM- (SELECT ifNull(avg(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))- GROUP BY day_start,- e.`$session_id`,- day_start)+ (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2075,25 +906,19 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter+# name: TestFormula.test_hour_interval_hour_level_relative'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count(DISTINCT e.`$session_id`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ (SELECT ifNull(sum(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 12.0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2112,19 +937,19 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter.1+# name: TestFormula.test_hour_interval_hour_level_relative.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT sum(total) AS count,+ (SELECT avg(total) AS count,day_start AS day_startFROM- (SELECT count(DISTINCT e.`$session_id`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ (SELECT ifNull(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'xyz'), ''), 'null'), '^"|"$', ''), 'Float64')), 0) AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 13:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 13:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2143,19 +968,31 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter[new_events_schema.1]+# name: TestFormula.test_regression_formula_with_session_duration_aggregation'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT sum(total) AS count,+ (SELECT avg(total) AS count,day_start AS day_startFROM- (SELECT count(DISTINCT e.`$session_id`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))+ (SELECT ifNull(avg(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ day_start AS day_start+ FROM+ (SELECT any(e__session.`$session_duration`) AS session_duration,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))+ GROUP BY day_start,+ e.`$session_id`,+ day_start)GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2174,7 +1011,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter[new_events_schema]+# name: TestFormula.test_regression_formula_with_session_duration_aggregation.1'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -2183,16 +1020,10 @@(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count(DISTINCT e.`$session_id`) AS total,+ (SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 12.0))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session end'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2211,7 +1042,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x+# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -2229,7 +1060,7 @@FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, '$autocapture'), less(e__session.`$session_duration`, 30.0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 12.0))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2248,7 +1079,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x.1+# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter.1'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -2260,13 +1091,7 @@(SELECT count(DISTINCT e.`$session_id`) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 500.0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2285,7 +1110,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x[new_events_schema.1]+# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -2296,14 +1121,14 @@FROM(SELECT count(DISTINCT e.`$session_id`) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 500.0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, '$autocapture'), less(e__session.`$session_duration`, 30.0))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -2322,7 +1147,7 @@use_hive_partitioning=0'''# ----# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x[new_events_schema]+# name: TestFormula.test_regression_formula_with_unique_sessions_2x_and_duration_filter_2x.1'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -2333,14 +1158,14 @@FROM(SELECT count(DISTINCT e.`$session_id`) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, '$autocapture'), less(e__session.`$session_duration`, 30.0))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'session start'), greater(e__session.`$session_duration`, 500.0))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_slope_graph_trends_query_runner.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_slope_graph_trends_query_runner.ambrindex dd95cac03c7e..ca1c43081a0b 100644--- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_slope_graph_trends_query_runner.ambr+++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_slope_graph_trends_query_runner.ambr@@ -50,547 +50,38 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_active_users_math_keeps_its_trailing_window[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-14 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-14 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-14 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2024-05-14 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-14 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_breakdown_produces_one_two_point_line_per_value- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_breakdown_produces_one_two_point_line_per_value[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^plan), '{}'), toJSONString(e.properties.^plan), if(isNull(e.properties.plan), NULL, if(startsWith(dynamicType(e.properties.plan), 'DateTime'), replaceOne(toString(e.properties.plan), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.plan), 'Array'), startsWith(dynamicType(e.properties.plan), 'Map'), startsWith(dynamicType(e.properties.plan), 'Tuple')), toJSONString(e.properties.plan), toString(e.properties.plan)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_formula_series- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_formula_series[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_groups_by_month_returning_first_and_last_month- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-01-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-02-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-31 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_groups_by_month_returning_first_and_last_month[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-01-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-02-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-31 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_hour_interval_first_and_last_hour- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 01:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:30:00', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_hour_interval_first_and_last_hour[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 01:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:30:00', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_keeps_the_query_property_filter_alongside_the_bucket_restriction- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_keeps_the_query_property_filter_alongside_the_bucket_restriction[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(if(notEquals(toJSONString(e.properties.^plan), '{}'), toJSONString(e.properties.^plan), if(isNull(e.properties.plan), NULL, if(startsWith(dynamicType(e.properties.plan), 'DateTime'), replaceOne(toString(e.properties.plan), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.plan), 'Array'), startsWith(dynamicType(e.properties.plan), 'Map'), startsWith(dynamicType(e.properties.plan), 'Tuple')), toJSONString(e.properties.plan), toString(e.properties.plan))))), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_last_bucket_is_the_current_partial_period_not_trimmed- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-04-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_last_bucket_is_the_current_partial_period_not_trimmed[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-04-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_monthly_active_math_keeps_its_trailing_window- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestSlopeGraphTrendsQueryRunner.test_monthly_active_math_keeps_its_trailing_window[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_breakdown_produces_one_two_point_line_per_value'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_valueFROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -605,7 +96,7 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_no_events_yields_zero_endpoints+# name: TestSlopeGraphTrendsQueryRunner.test_formula_series'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -636,9 +127,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_no_events_yields_zero_endpoints[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_groups_by_month_returning_first_and_last_month'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -646,9 +137,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))+ toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-03-31 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-01-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-02-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-03-31 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -667,9 +158,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_non_utc_team_timezone+# name: TestSlopeGraphTrendsQueryRunner.test_hour_interval_first_and_last_hour'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC')), toIntervalHour(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -677,9 +168,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'US/Pacific')) AS day_start+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'US/Pacific')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'US/Pacific'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'US/Pacific')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'US/Pacific')))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-14 00:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-14 04:30:00', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 01:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-14 04:30:00', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -698,9 +189,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_non_utc_team_timezone[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_keeps_the_query_property_filter_alongside_the_bucket_restriction'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -708,9 +199,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'US/Pacific')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'US/Pacific')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'US/Pacific'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'US/Pacific')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'US/Pacific')))))+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -729,9 +220,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_preserves_a_property_group_filter+# name: TestSlopeGraphTrendsQueryRunner.test_last_bucket_is_the_current_partial_period_not_trimmed'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -739,9 +230,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-04-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -760,20 +251,40 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_preserves_a_property_group_filter[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_monthly_active_math_keeps_its_trailing_window'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(if(notEquals(toJSONString(e.properties.^plan), '{}'), toJSONString(e.properties.^plan), if(isNull(e.properties.plan), NULL, if(startsWith(dynamicType(e.properties.plan), 'DateTime'), replaceOne(toString(e.properties.plan), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.plan), 'Array'), startsWith(dynamicType(e.properties.plan), 'Map'), startsWith(dynamicType(e.properties.plan), 'Tuple')), toJSONString(e.properties.plan), toString(e.properties.plan))))), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))- GROUP BY day_start)+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_start+ FROM+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))+ GROUP BY d.timestamp+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-04-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2024-05-13 23:59:59', 'UTC')))))GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESC@@ -791,9 +302,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_relative_date_range+# name: TestSlopeGraphTrendsQueryRunner.test_no_events_yields_zero_endpoints'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -803,7 +314,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-08 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-09 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -822,9 +333,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_relative_date_range[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_non_utc_team_timezone'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -832,9 +343,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-08 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-09 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))+ toStartOfDay(toTimeZone(e.timestamp, 'US/Pacific')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'US/Pacific'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'US/Pacific')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'US/Pacific'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'US/Pacific')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'US/Pacific')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -853,7 +364,7 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_returns_first_and_last_day_buckets_ignoring_the_middle+# name: TestSlopeGraphTrendsQueryRunner.test_preserves_a_property_group_filter'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -865,7 +376,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'plan'), ''), 'null'), '^"|"$', ''), 'paid'), 0), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC'))))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -884,9 +395,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_returns_first_and_last_day_buckets_ignoring_the_middle[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_relative_date_range'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -895,8 +406,8 @@FROM(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-06-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-06-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-08 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-09 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-15 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -915,9 +426,9 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_single_bucket_range_yields_a_one_point_series+# name: TestSlopeGraphTrendsQueryRunner.test_returns_first_and_last_day_buckets_ignoring_the_middle'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-31 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -925,9 +436,9 @@day_start AS day_startFROM(SELECT count() AS total,- toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-31 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-31 23:59:59', 6, 'UTC')))))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -946,7 +457,7 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_single_bucket_range_yields_a_one_point_series[new_events_schema]+# name: TestSlopeGraphTrendsQueryRunner.test_single_bucket_range_yields_a_one_point_series'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalMonth(1)), toIntervalMonth(number)), range(0, plus(coalesce(dateDiff('month', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalMonth(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-31 23:59:59', 'UTC')), toIntervalMonth(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)@@ -957,7 +468,7 @@FROM(SELECT count() AS total,toStartOfMonth(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-31 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-06-01 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-31 23:59:59', 6, 'UTC')))))GROUP BY day_start)GROUP BY day_start@@ -1008,37 +519,6 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_smoothing_does_not_starve_the_last_point[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestSlopeGraphTrendsQueryRunner.test_unique_users_math_is_per_bucket'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,@@ -1077,44 +557,6 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_unique_users_math_is_per_bucket[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-10 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-01 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-02 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-10 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestSlopeGraphTrendsQueryRunner.test_week_interval_scan_filter_aligns_with_the_buckets'''SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2024-05-28 23:59:59', 'UTC')), 0))), 1))) AS date,@@ -1146,34 +588,3 @@use_hive_partitioning=0'''# ----# name: TestSlopeGraphTrendsQueryRunner.test_week_interval_scan_filter_aligns_with_the_buckets[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2024-05-28 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2024-05-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2024-05-28 23:59:59', 'UTC'))), equals(e.event, '$pageview'), or(and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-04-28 00:00:00', 6, 'UTC')), less(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-05 00:00:00', 6, 'UTC'))), and(greaterOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-26 00:00:00', 6, 'UTC')), lessOrEquals(e.timestamp, parseDateTime64BestEffortOrNull('2024-05-28 23:59:59', 6, 'UTC')))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambrindex 795858869d32..a29b8255f7a4 100644--- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr+++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr@@ -70,57 +70,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_action_filtering_with_cohort[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$bool_prop'), ''), 'null'), '^"|"$', '') AS `properties___$bool_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 2))))), ifNull(equals(e__person.`properties___$bool_prop`, 'x'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_breakdown_by_group_props_person_on_events'''SELECT groupArray(1)(date)[1] AS date,@@ -268,129 +217,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_by_group_props_person_on_events[new_events_schema.1]- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events,- source.event_distinct_ids AS event_distinct_ids- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- groupUniqArray(distinct_id) AS event_distinct_ids,- groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events,- max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id,- toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- e.distinct_id AS distinct_id- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), ifNull(equals(ifNull(nullIf(leftUTF8(toString(e__group_0.properties___industry), 400), ''), '$$_posthog_breakdown_null_$$'), 'technology'), 0), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) 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 actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events, max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id, toTimeZone(e.timestamp, 'UTC') AS timestamp, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, e.distinct_id AS distinct_id- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), ifNull(equals(ifNull(nullIf(leftUTF8(toString(e__group_0.properties___industry), 400), ''), '$$_posthog_breakdown_null_$$'), 'technology'), 0), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY source.event_count DESC- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_by_group_props_person_on_events[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__group_0.properties___industry), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_breakdown_by_group_props_with_person_filter_person_on_events'''SELECT groupArray(1)(date)[1] AS date,@@ -445,60 +271,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_by_group_props_with_person_filter_person_on_events[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__group_0.properties___industry), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(if(notEquals(toJSONString(e.person_properties.^key), '{}'), toJSONString(e.person_properties.^key), if(isNull(e.person_properties.key), NULL, if(startsWith(dynamicType(e.person_properties.key), 'DateTime'), replaceOne(toString(e.person_properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.person_properties.key), 'Array'), startsWith(dynamicType(e.person_properties.key), 'Map'), startsWith(dynamicType(e.person_properties.key), 'Tuple')), toJSONString(e.person_properties.key), toString(e.person_properties.key))))), 'value'), 0))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_breakdown_filtering_with_properties_in_new_format'''SELECT groupArray(1)(date)[1] AS date,@@ -683,199 +455,15 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_filtering_with_properties_in_new_format[new_events_schema.1]+# name: TestTrends.test_breakdown_weekly_active_users_aggregated'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT sum(total) AS total,+ if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e.properties.`$current_url`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(and(equals(e.properties.`$browser`, 'Firefox'), isNotNull(e.properties.`$browser`)), and(equals(e.properties.`$os`, 'Windows'), isNotNull(e.properties.`$os`))), and(equals(e.properties.`$os`, 'Mac'), isNotNull(e.properties.`$os`)))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_filtering_with_properties_in_new_format[new_events_schema.2]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e.properties.`$current_url`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'), or(and(equals(e.properties.`$browser`, 'Firefox'), isNotNull(e.properties.`$browser`)), and(equals(e.properties.`$os`, 'Windows'), isNotNull(e.properties.`$os`))), and(equals(e.properties.`$os`, 'Mac'), isNotNull(e.properties.`$os`)))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_filtering_with_properties_in_new_format[new_events_schema.3]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e.properties.`$current_url`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(and(equals(e.properties.`$browser`, 'Firefox'), isNotNull(e.properties.`$browser`)), and(equals(e.properties.`$os`, 'Windows'), isNotNull(e.properties.`$os`))), and(equals(e.properties.`$os`, 'Mac'), isNotNull(e.properties.`$os`)))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_filtering_with_properties_in_new_format[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e.properties.`$current_url`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'), or(and(equals(e.properties.`$browser`, 'Firefox'), isNotNull(e.properties.`$browser`)), and(equals(e.properties.`$os`, 'Windows'), isNotNull(e.properties.`$os`))), and(equals(e.properties.`$os`, 'Mac'), isNotNull(e.properties.`$os`)))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_weekly_active_users_aggregated- '''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT count AS total,+ breakdown_value AS breakdown_value,+ row_number() OVER (+ ORDER BY total DESC) AS row_numberFROM(SELECT sum(total) AS count,breakdown_value AS breakdown_value@@ -933,72 +521,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_weekly_active_users_aggregated[new_events_schema]- '''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number- FROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT actor_id) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT d.timestamp AS timestamp,- e.actor_id AS actor_id,- e.breakdown_value AS breakdown_value- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-11 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-11 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-11 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp,- e.actor_id,- breakdown_value- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-11 23:59:59', 'UTC'))))- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_breakdown_weekly_active_users_daily_based_on_action'''@@ -1091,89 +613,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_weekly_active_users_daily_based_on_action[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts,- e.breakdown_value AS breakdown_value- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, '$pageview'), and(in(e__person.properties___name, tuple('p1', 'p2', 'p3')), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))))), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp,- breakdown_value- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))))- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_breakdown_with_filter_groups_person_on_events+# name: TestTrends.test_breakdown_with_filter_groups_person_on_events'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -1227,60 +667,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_with_filter_groups_person_on_events[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__group_0.properties___industry, 'finance'), 0))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_breakdown_with_filter_groups_person_on_events_v2'''@@ -1351,67 +737,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_breakdown_with_filter_groups_person_on_events_v2[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__group_0.properties___industry, 'finance'), 0))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling'''SELECT groupArray(1)(date)[1] AS date,@@ -1624,45 +949,60 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.4+# name: TestTrends.test_filter_events_by_precalculated_cohort'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value++ SELECT count(DISTINCT person_id)+ FROM cohortpeople+ WHERE team_id = 99999+ AND cohort_id = 99999+ AND version = 0+ '''+# ---+# name: TestTrends.test_filter_events_by_precalculated_cohort.1+ '''++ SELECT count(DISTINCT person_id)+ FROM cohortpeople+ WHERE team_id = 99999+ AND cohort_id = 99999+ AND version = 0+ '''+# ---+# name: TestTrends.test_filter_events_by_precalculated_cohort.2+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC'))), equals(e.event, 'event_name'), ifNull(equals(e__person.properties___name, 'Jane'), 0))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1677,4035 +1017,39 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling[new_events_schema.1]+# name: TestTrends.test_filtering_by_multiple_groups_person_on_events'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling[new_events_schema.2]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling[new_events_schema.3]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling[new_events_schema.4]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filter_events_by_precalculated_cohort- '''-- SELECT count(DISTINCT person_id)- FROM cohortpeople- WHERE team_id = 99999- AND cohort_id = 99999- AND version = 0- '''-# ----# name: TestTrends.test_filter_events_by_precalculated_cohort.1- '''-- SELECT count(DISTINCT person_id)- FROM cohortpeople- WHERE team_id = 99999- AND cohort_id = 99999- AND version = 0- '''-# ----# name: TestTrends.test_filter_events_by_precalculated_cohort.2- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC'))), equals(e.event, 'event_name'), ifNull(equals(e__person.properties___name, 'Jane'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filter_events_by_precalculated_cohort[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-26 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-02 23:59:59', 'UTC'))), equals(e.event, 'event_name'), ifNull(equals(e__person.properties___name, 'Jane'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_by_multiple_groups_person_on_events- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_by_multiple_groups_person_on_events.1- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events,- source.event_distinct_ids AS event_distinct_ids- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- groupUniqArray(distinct_id) AS event_distinct_ids,- groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events,- max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id,- toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- e.distinct_id AS distinct_id- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) 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 actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events, max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id, toTimeZone(e.timestamp, 'UTC') AS timestamp, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, e.distinct_id AS distinct_id- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index, groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY source.event_count DESC- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_by_multiple_groups_person_on_events.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, ['']))- GROUP BY session_replay_events.session_id- HAVING and(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), equals(max(session_replay_events.is_deleted), 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_by_multiple_groups_person_on_events[new_events_schema.1]- '''- SELECT persons.id AS id,- persons.created_at AS created_at,- source.event_count AS event_count,- source.matching_events AS matching_events,- source.event_distinct_ids AS event_distinct_ids- FROM- (SELECT actor_id AS actor_id,- count() AS event_count,- groupUniqArray(distinct_id) AS event_distinct_ids,- groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events,- max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id,- toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- e.distinct_id AS distinct_id- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source- INNER JOIN- (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) 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 actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events, max(timestamp) AS last_seen- FROM- (SELECT e.person_id AS actor_id, toTimeZone(e.timestamp, 'UTC') AS timestamp, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, e.distinct_id AS distinct_id- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index, groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))- GROUP BY actor_id) AS source)))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)- ORDER BY source.event_count DESC- 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_by_multiple_groups_person_on_events[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 2))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_with_group_props_person_on_events- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'key'), ''), 'null'), '^"|"$', ''), 'value'), 0)))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_filtering_with_group_props_person_on_events[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(if(notEquals(toJSONString(e.person_properties.^key), '{}'), toJSONString(e.person_properties.^key), if(isNull(e.person_properties.key), NULL, if(startsWith(dynamicType(e.person_properties.key), 'DateTime'), replaceOne(toString(e.person_properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.person_properties.key), 'Array'), startsWith(dynamicType(e.person_properties.key), 'Map'), startsWith(dynamicType(e.person_properties.key), 'Tuple')), toJSONString(e.person_properties.key), toString(e.person_properties.key))))), 'value'), 0)))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts,- e.breakdown_value AS breakdown_value- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp,- breakdown_value- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start,- breakdown_value_1 AS breakdown_value_1- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts,- e.breakdown_value_1 AS breakdown_value_1- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value_1) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp,- breakdown_value_1- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start,- breakdown_value_1 AS breakdown_value_1- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts,- e.breakdown_value_1 AS breakdown_value_1- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value_1) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp,- breakdown_value_1- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts,- e.breakdown_value AS breakdown_value- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id,- breakdown_value) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp,- breakdown_value- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_non_deterministic_timezones- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toStartOfWeek(assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'US/Pacific'), 0) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_non_deterministic_timezones[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toStartOfWeek(assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'US/Pacific'), 0) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_filtering_in_cohort_in_action- '''-- SELECT count(DISTINCT person_id)- FROM cohortpeople- WHERE team_id = 99999- AND cohort_id = 99999- AND version = 0- '''-# ----# name: TestTrends.test_person_filtering_in_cohort_in_action.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_filtering_in_cohort_in_action.2- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_filtering_in_cohort_in_action[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_filtering_in_cohort_in_action[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering_clashing_with_event_property- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering_clashing_with_event_property.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'name'), ''), 'null'), '^"|"$', ''), '1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering_clashing_with_event_property[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(if(notEquals(toJSONString(e.properties.^name), '{}'), toJSONString(e.properties.^name), if(isNull(e.properties.name), NULL, if(startsWith(dynamicType(e.properties.name), 'DateTime'), replaceOne(toString(e.properties.name), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.name), 'Array'), startsWith(dynamicType(e.properties.name), 'Map'), startsWith(dynamicType(e.properties.name), 'Tuple')), toJSONString(e.properties.name), toString(e.properties.name))))), '1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_person_property_filtering_clashing_with_event_property[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'distinctid2'- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2.2- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'distinctid2'- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.2- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'distinctid3'- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.3- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.4- '''-- SELECT DISTINCT person_id- FROM events- WHERE team_id = 99999- AND distinct_id = 'distinctid2'- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.5- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override[new_events_schema.2]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily.2- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily.3- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily.4- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$os'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily[new_events_schema.2]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily[new_events_schema.3]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily[new_events_schema.4]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e.properties.`$os`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_daily[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_hourly_relative_from- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_hourly_relative_from.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_hourly_relative_from[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_hourly_relative_from[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_weekly- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_weekly.1- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 3))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 3) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_weekly[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 3))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 3) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_timezones_weekly[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(or(ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), or(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'safari'), 0))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'chrome'), 0)), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0), ifNull(ilike(toString(e__person.properties___email), '%@posthog.com%'), 0)))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'chrome'), 0)), and(ifNull(equals(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key))))), 'val'), 0), ifNull(ilike(toString(e__person.properties___email), '%@posthog.com%'), 0)))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(or(ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), ifNull(equals(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key))))), 'val'), 0)), or(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'safari'), 0))))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__person.`properties___$some_prop`, 'some_val'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.2- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.3- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.4- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.distinct_id AS actor_id- FROM events AS e- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.5- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.distinct_id AS actor_id- FROM events AS e- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id.6- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_prop'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__person.`properties___$some_prop`, 'some_val'), 0))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.2]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.3]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value_1)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.4]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.distinct_id AS actor_id- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.5]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.distinct_id AS actor_id- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema.6]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_prop`), '{}'), toJSONString(e.properties.^`$some_prop`), if(isNull(e.properties.`$some_prop`), NULL, if(startsWith(dynamicType(e.properties.`$some_prop`), 'DateTime'), replaceOne(toString(e.properties.`$some_prop`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_prop`), 'Array'), startsWith(dynamicType(e.properties.`$some_prop`), 'Map'), startsWith(dynamicType(e.properties.`$some_prop`), 'Tuple')), toJSONString(e.properties.`$some_prop`), toString(e.properties.`$some_prop`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_aggregate_by_distinct_id[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.distinct_id) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count.1- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count.2- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count[new_events_schema.1]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count[new_events_schema.2]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_any_event_total_count[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT sum(total) AS count,+ day_start AS day_startFROM(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))+ FROM events AS e+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,+ groups.group_type_index AS index,+ groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 2))+ GROUP BY groups.group_type_index,+ groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)+ 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_breakdown_cumulative- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_breakdown_cumulative.1- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_breakdown_cumulative[new_events_schema.1]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_trends_breakdown_cumulative[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5720,165 +1064,137 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_normalize_url+# name: TestTrends.test_filtering_by_multiple_groups_person_on_events.1'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT persons.id AS id,+ persons.created_at AS created_at,+ source.event_count AS event_count,+ source.matching_events AS matching_events,+ source.event_distinct_ids AS event_distinct_idsFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number+ (SELECT actor_id AS actor_id,+ count() AS event_count,+ groupUniqArray(distinct_id) AS event_distinct_ids,+ groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events,+ max(timestamp) AS last_seenFROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(empty(trim(TRAILING '/?#'- FROM replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''))), '/', trim(TRAILING '/?#'- FROM replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0+ (SELECT e.person_id AS actor_id,+ toTimeZone(e.timestamp, 'UTC') AS timestamp,+ e.uuid AS uuid,+ e.`$session_id` AS `$session_id`,+ e.`$window_id` AS `$window_id`,+ e.distinct_id AS distinct_id+ FROM events AS e+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name,+ groups.group_type_index AS index,+ groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 2))+ GROUP BY groups.group_type_index,+ groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)+ 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))+ GROUP BY actor_id) AS source+ INNER JOIN+ (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) 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 actor_id AS actor_id, count() AS event_count, groupUniqArray(distinct_id) AS event_distinct_ids, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events, max(timestamp) AS last_seen+ FROM+ (SELECT e.person_id AS actor_id, toTimeZone(e.timestamp, 'UTC') AS timestamp, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, e.distinct_id AS distinct_id+ FROM events AS e+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___name, groups.group_type_index AS index, groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 2))+ GROUP BY groups.group_type_index, groups.group_key) AS e__group_2 ON equals(e.`$group_2`, e__group_2.key)+ 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ WHERE and(equals(e.team_id, 99999), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up')))+ GROUP BY actor_id) AS source)))+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id)+ ORDER BY source.event_count DESC+ 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_normalize_url[new_events_schema]+# name: TestTrends.test_filtering_by_multiple_groups_person_on_events.2'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT day_start AS day_start,- sum(count) OVER (PARTITION BY breakdown_value- ORDER BY day_start ASC) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,- ifNull(nullIf(leftUTF8(toString(if(empty(trim(TRAILING '/?#'- FROM e.properties.`$current_url`)), '/', trim(TRAILING '/?#'- FROM e.properties.`$current_url`))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- ORDER BY day_start ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0+ 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(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), equals(max(session_replay_events.is_deleted), 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown+# name: TestTrends.test_filtering_with_group_props_person_on_events'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value)- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ 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 e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'key'), ''), 'null'), '^"|"$', ''), 'value'), 0)))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5893,43 +1209,72 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.1+# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM(SELECT sum(total) AS count,+ day_start AS day_start,breakdown_value AS breakdown_valueFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_start,breakdown_value AS breakdown_valueFROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value)- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts,+ e.breakdown_value AS breakdown_value+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id,+ breakdown_value) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))+ GROUP BY d.timestamp,+ breakdown_value+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5944,43 +1289,72 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.2+# name: TestTrends.test_mau_with_breakdown_filtering_and_prop_filter.1'''- SELECT sum(total) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_valueFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM(SELECT sum(total) AS count,+ day_start AS day_start,[ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_valueFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_start,breakdown_value_1 AS breakdown_value_1FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value_1)- GROUP BY breakdown_value_1)- GROUP BY breakdown_value_1- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts,+ e.breakdown_value_1 AS breakdown_value_1+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id,+ breakdown_value_1) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))+ GROUP BY d.timestamp,+ breakdown_value_1+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')))))+ GROUP BY day_start,+ breakdown_value_1+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)WHERE arrayExists(x -> isNotNull(x), breakdown_value)GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,- breakdown_value ASC+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5995,43 +1369,89 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.3+# name: TestTrends.test_non_deterministic_timezones'''- SELECT sum(total) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), 0), toStartOfWeek(assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific')), 0))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value_1)- GROUP BY breakdown_value_1)- GROUP BY breakdown_value_1- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)+ (SELECT count() AS total,+ toStartOfWeek(toTimeZone(e.timestamp, 'US/Pacific'), 0) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2022-10-31 00:00:00', 'US/Pacific')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2022-11-30 23:59:59', 'US/Pacific'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESC+ LIMIT 50000 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestTrends.test_person_filtering_in_cohort_in_action+ '''++ SELECT count(DISTINCT person_id)+ FROM cohortpeople+ WHERE team_id = 99999+ AND cohort_id = 99999+ AND version = 0+ '''+# ---+# name: TestTrends.test_person_filtering_in_cohort_in_action.1+ '''+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ FROM+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_number+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), and(equals(e.event, 'sign up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ (SELECT cohortpeople.person_id AS person_id+ FROM cohortpeople+ WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,- breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6046,43 +1466,40 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema.1]+# name: TestTrends.test_person_property_filtering'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value)- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6097,43 +1514,40 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema.2]+# name: TestTrends.test_person_property_filtering_clashing_with_event_property'''- SELECT sum(total) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value_1)- GROUP BY breakdown_value_1)- GROUP BY breakdown_value_1- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6148,43 +1562,23 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema.3]+# name: TestTrends.test_person_property_filtering_clashing_with_event_property.1'''- SELECT sum(total) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value_1)- GROUP BY breakdown_value_1)- GROUP BY breakdown_value_1- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'name'), ''), 'null'), '^"|"$', ''), '1'), 0))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6199,43 +1593,32 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema]+# name: TestTrends.test_same_day_with_person_on_events_v2'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'distinctid2'+ '''+# ---+# name: TestTrends.test_same_day_with_person_on_events_v2.1+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`,- breakdown_value)- GROUP BY breakdown_value)- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6250,19 +1633,26 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range+# name: TestTrends.test_same_day_with_person_on_events_v2.2'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6281,19 +1671,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range.1+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'distinctid2'+ '''+# ---+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.1+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6312,19 +1718,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range.2+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.2'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'distinctid3'+ '''+# ---+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.3+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6343,19 +1765,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range.3+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.4'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'distinctid2'+ '''+# ---+# name: TestTrends.test_same_day_with_person_on_events_v2_latest_override.5+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-03 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-03 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6374,9 +1812,9 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range[new_events_schema.1]+# name: TestTrends.test_timezones_daily'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -6385,8 +1823,8 @@FROM(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6405,19 +1843,26 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range[new_events_schema.2]+# name: TestTrends.test_timezones_daily.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-22 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6436,20 +1881,40 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range[new_events_schema.3]+# name: TestTrends.test_timezones_daily.2'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_start+ FROM+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))+ GROUP BY d.timestamp+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')))))GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESC@@ -6467,9 +1932,9 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_compare_day_interval_relative_range[new_events_schema]+# name: TestTrends.test_timezones_daily.3'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM@@ -6478,8 +1943,8 @@FROM(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6498,23 +1963,45 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_aggregated+# name: TestTrends.test_timezones_daily.4'''- SELECT total AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT avg(total) AS total+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT count() AS total- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)))+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$os'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6529,14 +2016,18 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_aggregated[new_events_schema]+# name: TestTrends.test_timezones_hourly_relative_from'''- SELECT total AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT avg(total) AS total+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT count() AS total- FROM events_json AS e+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -6544,8 +2035,11 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6560,47 +2054,23 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_aggregated_with_event_property_breakdown_with_sampling+# name: TestTrends.test_timezones_hourly_relative_from.1'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number- FROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT total AS total,- breakdown_value AS breakdown_value- FROM- (SELECT avg(total) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'color'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY breakdown_value))- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC')), toIntervalHour(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count() AS total,+ toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 00:00:00', 'UTC'))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-05 10:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6615,47 +2085,23 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_aggregated_with_event_property_breakdown_with_sampling[new_events_schema]+# name: TestTrends.test_timezones_weekly'''- SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 0))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT count AS total,- breakdown_value AS breakdown_value,- row_number() OVER (- ORDER BY total DESC) AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- breakdown_value AS breakdown_value- FROM- (SELECT total AS total,- breakdown_value AS breakdown_value- FROM- (SELECT avg(total) AS total,- breakdown_value AS breakdown_value- FROM- (SELECT count() AS total,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^color), '{}'), toJSONString(e.properties.^color), if(isNull(e.properties.color), NULL, if(startsWith(dynamicType(e.properties.color), 'DateTime'), replaceOne(toString(e.properties.color), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.color), 'Array'), startsWith(dynamicType(e.properties.color), 'Map'), startsWith(dynamicType(e.properties.color), 'Tuple')), toJSONString(e.properties.color), toString(e.properties.color)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- breakdown_value)- GROUP BY breakdown_value))- GROUP BY breakdown_value- ORDER BY breakdown_value ASC)- ORDER BY total DESC,- breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ (SELECT count() AS total,+ toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6670,35 +2116,20 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_daily+# name: TestTrends.test_timezones_weekly.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), 3), toStartOfWeek(assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC')), 3))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT total AS total,- day_start AS day_start- FROM- (SELECT avg(total) AS total,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- day_start)- GROUP BY day_start))+ (SELECT count() AS total,+ toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 3) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-26 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESC@@ -6716,38 +2147,57 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_count_per_user_average_daily[new_events_schema]+# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT total AS total,- day_start AS day_start+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_valueFROM- (SELECT avg(total) AS total,- day_start AS day_start- FROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- day_start)- GROUP BY day_start))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(or(ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), or(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'safari'), 0))))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6762,23 +2212,57 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_groups_per_day+# name: TestTrends.test_trend_breakdown_user_props_with_filter_with_partial_property_pushdowns.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT count(DISTINCT e.`$group_0`) AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(nullIf(nullIf(e.`$group_0`, ''), 'null'), ''), 1), notEquals(e.`$group_0`, ''))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(e__person.properties___email), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-07-01 23:59:59', 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'chrome'), 0)), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0), ifNull(ilike(toString(e__person.properties___email), '%@posthog.com%'), 0)))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6793,19 +2277,19 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_groups_per_day[new_events_schema]+# name: TestTrends.test_trends_aggregate_by_distinct_id'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT count(DISTINCT e.`$group_0`) AS total,+ (SELECT count(DISTINCT e.distinct_id) AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(e.properties.`$group_0`, ''), 1), notEquals(e.`$group_0`, ''))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -6824,26 +2308,38 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_groups_per_day_cumulative+# name: TestTrends.test_trends_aggregate_by_distinct_id.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT e.`$group_0`) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(nullIf(nullIf(e.`$group_0`, ''), 'null'), ''), 1), notEquals(e.`$group_0`, ''))- GROUP BY e.`$group_0`)- GROUP BY day_start- ORDER BY day_start ASC)+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count(DISTINCT e.distinct_id) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__person.`properties___$some_prop`, 'some_val'), 0))+ GROUP BY day_start)+ GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,@@ -6860,28 +2356,55 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_groups_per_day_cumulative[new_events_schema]+# name: TestTrends.test_trends_aggregate_by_distinct_id.2'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM(SELECT sum(total) AS count,- day_start AS day_start+ day_start AS day_start,+ breakdown_value AS breakdown_valueFROM- (SELECT count(DISTINCT e.`$group_0`) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(e.properties.`$group_0`, ''), 1), notEquals(e.`$group_0`, ''))- GROUP BY e.`$group_0`)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT count(DISTINCT e.distinct_id) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6896,28 +2419,55 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_cumulative+# name: TestTrends.test_trends_aggregate_by_distinct_id.3'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_valueFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM(SELECT sum(total) AS count,- day_start AS day_start+ day_start AS day_start,+ [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_valueFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ (SELECT count(DISTINCT e.distinct_id) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ breakdown_value_1)+ GROUP BY day_start,+ breakdown_value_1+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE arrayExists(x -> isNotNull(x), breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6932,26 +2482,34 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_cumulative.1+# name: TestTrends.test_trends_aggregate_by_distinct_id.4'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_startFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ e.distinct_id AS actor_id+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(30))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(30)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(30))))+ GROUP BY d.timestamp+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))+ GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,@@ -6968,26 +2526,34 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_cumulative[new_events_schema.1]+# name: TestTrends.test_trends_aggregate_by_distinct_id.5'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_startFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ e.distinct_id AS actor_id+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'sign up'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))+ GROUP BY d.timestamp+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')))))+ GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,@@ -7004,28 +2570,38 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_cumulative[new_events_schema]+# name: TestTrends.test_trends_aggregate_by_distinct_id.6'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM(SELECT sum(total) AS count,- day_start AS day_start+ day_start AS day_start,+ breakdown_value AS breakdown_valueFROM- (SELECT count() AS total,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT count(DISTINCT e.distinct_id) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_prop'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-24 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-31 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7040,33 +2616,21 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_dau_cumulative+# name: TestTrends.test_trends_any_event_total_count'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id))- GROUP BY day_start- ORDER BY day_start ASC)+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))))+ GROUP BY day_start)+ GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,@@ -7083,33 +2647,21 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_dau_cumulative.1+# name: TestTrends.test_trends_any_event_total_count.1'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id))- GROUP BY day_start- ORDER BY day_start ASC)+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_startORDER BY day_start ASC)ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,@@ -7126,35 +2678,51 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_dau_cumulative[new_events_schema.1]+# name: TestTrends.test_trends_breakdown_cumulative'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT day_start AS day_start,+ sum(count) OVER (PARTITION BY breakdown_value+ ORDER BY day_start ASC) AS count,+ breakdown_value AS breakdown_valueFROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id))- GROUP BY day_start+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,+ min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)ORDER BY day_start ASC)- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7169,35 +2737,53 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_per_day_dau_cumulative[new_events_schema]+# name: TestTrends.test_trends_breakdown_normalize_url'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total+ SELECT groupArray(1)(date)[1] AS date,+ arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT day_start AS day_start,- sum(count) OVER (- ORDER BY day_start ASC) AS count+ (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total,+ breakdown_value AS breakdown_value,+ rowNumberInAllBlocks() AS row_numberFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT day_start AS day_start,+ sum(count) OVER (PARTITION BY breakdown_value+ ORDER BY day_start ASC) AS count,+ breakdown_value AS breakdown_valueFROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id))- GROUP BY day_start+ (SELECT sum(total) AS count,+ day_start AS day_start,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,+ min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start,+ ifNull(nullIf(leftUTF8(toString(if(empty(trim(TRAILING '/?#'+ FROM replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''))), '/', trim(TRAILING '/?#'+ FROM replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', '')))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ breakdown_value)+ GROUP BY day_start,+ breakdown_value+ ORDER BY day_start ASC,+ breakdown_value ASC)ORDER BY day_start ASC)- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7212,7 +2798,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown+# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown'''SELECT sum(total) AS total,if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value@@ -7229,31 +2815,14 @@breakdown_value AS breakdown_valueFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_valueFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)LEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY e.`$session_id`,breakdown_value)@@ -7280,10 +2849,10 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown.1+# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.1'''SELECT sum(total) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM(SELECT count AS total,breakdown_value AS breakdown_value,@@ -7291,49 +2860,32 @@ORDER BY total DESC) AS row_numberFROM(SELECT sum(total) AS count,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value+ breakdown_value AS breakdown_valueFROM(SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1+ breakdown_value AS breakdown_valueFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_valueFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)LEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY e.`$session_id`,- breakdown_value_1)- GROUP BY breakdown_value_1)- GROUP BY breakdown_value_1+ breakdown_value)+ GROUP BY breakdown_value)+ GROUP BY breakdown_valueORDER BY breakdown_value ASC)ORDER BY total DESC,breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)+ WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,- breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,+ breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7348,7 +2900,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema.1]+# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.2'''SELECT sum(total) AS total,arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value@@ -7365,31 +2917,14 @@breakdown_value_1 AS breakdown_value_1FROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY e.`$session_id`,breakdown_value_1)@@ -7416,10 +2951,10 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown[new_events_schema]+# name: TestTrends.test_trends_breakdown_with_session_property_single_aggregate_math_and_breakdown.3'''SELECT sum(total) AS total,- if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_valueFROM(SELECT count AS total,breakdown_value AS breakdown_value,@@ -7427,49 +2962,32 @@ORDER BY total DESC) AS row_numberFROM(SELECT sum(total) AS count,- breakdown_value AS breakdown_value+ [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_valueFROM(SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value+ breakdown_value_1 AS breakdown_value_1FROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY e.`$session_id`,- breakdown_value)- GROUP BY breakdown_value)- GROUP BY breakdown_value+ breakdown_value_1)+ GROUP BY breakdown_value_1)+ GROUP BY breakdown_value_1ORDER BY breakdown_value ASC)ORDER BY total DESC,breakdown_value ASC)- WHERE isNotNull(breakdown_value)+ WHERE arrayExists(x -> isNotNull(x), breakdown_value)GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,- breakdown_value ASC+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,+ breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7484,17 +3002,17 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_hogql_math+# name: TestTrends.test_trends_compare_day_interval_relative_range'''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(accurateCastOrNull(plus(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'x'), ''), 'null'), '^"|"$', ''), 'Float64')), 1000), 'Float64'), 0) AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)@@ -7515,18 +3033,49 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_hogql_math[new_events_schema]+# name: TestTrends.test_trends_compare_day_interval_relative_range.1'''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(accurateCastOrNull(plus(avg(accurateCastOrNull(if(notEquals(toJSONString(e.properties.^x), '{}'), toJSONString(e.properties.^x), if(isNull(e.properties.x), NULL, if(startsWith(dynamicType(e.properties.x), 'DateTime'), replaceOne(toString(e.properties.x), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.x), 'Array'), startsWith(dynamicType(e.properties.x), 'Map'), startsWith(dynamicType(e.properties.x), 'Tuple')), toJSONString(e.properties.x), toString(e.properties.x))))), 'Float64')), 1000), 'Float64'), 0) AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-21 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2019-12-28 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESC+ LIMIT 50000 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestTrends.test_trends_compare_day_interval_relative_range.2+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS eWHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_start@@ -7546,21 +3095,155 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_single_aggregate_math+# name: TestTrends.test_trends_count_per_user_average_aggregated'''- SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total+ SELECT total AS totalFROM- (SELECT any(e__session.`$session_duration`) AS session_duration- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`- ORDER BY 1 DESC)+ (SELECT avg(total) AS total+ FROM+ (SELECT count() AS total+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)))+ LIMIT 50000 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestTrends.test_trends_count_per_user_average_aggregated_with_event_property_breakdown_with_sampling+ '''+ SELECT sum(total) AS total,+ if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ FROM+ (SELECT count AS total,+ breakdown_value AS breakdown_value,+ row_number() OVER (+ ORDER BY total DESC) AS row_number+ FROM+ (SELECT sum(total) AS count,+ breakdown_value AS breakdown_value+ FROM+ (SELECT total AS total,+ breakdown_value AS breakdown_value+ FROM+ (SELECT avg(total) AS total,+ breakdown_value AS breakdown_value+ FROM+ (SELECT count() AS total,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'color'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ breakdown_value)+ GROUP BY breakdown_value))+ GROUP BY breakdown_value+ ORDER BY breakdown_value ASC)+ ORDER BY total DESC,+ breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,+ breakdown_value ASC+ LIMIT 50000 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestTrends.test_trends_count_per_user_average_daily+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT total AS total,+ day_start AS day_start+ FROM+ (SELECT avg(total) AS total,+ day_start AS day_start+ FROM+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), equals(e.event, 'viewed video'), greaterOrEquals(e.timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(0))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-07 23:59:59', 'UTC'))))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ day_start)+ GROUP BY day_start))+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESC+ LIMIT 50000 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,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestTrends.test_trends_groups_per_day+ '''+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count(DISTINCT e.`$group_0`) AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(nullIf(nullIf(e.`$group_0`, ''), 'null'), ''), 1), notEquals(e.`$group_0`, ''))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7575,21 +3258,28 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_single_aggregate_math.1+# name: TestTrends.test_trends_groups_per_day_cumulative'''- SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS totalFROM- (SELECT any(e__session.`$session_duration`) AS session_duration- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`- ORDER BY 1 DESC)+ (SELECT day_start AS day_start,+ sum(count) OVER (+ ORDER BY day_start ASC) AS count+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count(DISTINCT e.`$group_0`) AS total,+ min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-30 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-06 23:59:59', 'UTC'))), equals(e.event, 'viewed video'), ifNull(notEquals(nullIf(nullIf(e.`$group_0`, ''), 'null'), ''), 1), notEquals(e.`$group_0`, ''))+ GROUP BY e.`$group_0`)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7604,21 +3294,28 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_single_aggregate_math[new_events_schema.1]+# name: TestTrends.test_trends_per_day_cumulative'''- SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS totalFROM- (SELECT any(e__session.`$session_duration`) AS session_duration- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`- ORDER BY 1 DESC)+ (SELECT day_start AS day_start,+ sum(count) OVER (+ ORDER BY day_start ASC) AS count+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count() AS total,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7633,21 +3330,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_single_aggregate_math[new_events_schema]+# name: TestTrends.test_trends_per_day_dau_cumulative'''- SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS totalFROM- (SELECT any(e__session.`$session_duration`) AS session_duration- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY e.`$session_id`- ORDER BY 1 DESC)+ (SELECT day_start AS day_start,+ sum(count) OVER (+ ORDER BY day_start ASC) AS count+ FROM+ (SELECT sum(total) AS count,+ day_start AS day_start+ FROM+ (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,+ min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id))+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7662,35 +3373,60 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math+# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown'''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT sum(total) AS total,+ if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT count AS total,+ breakdown_value AS breakdown_value,+ row_number() OVER (+ ORDER BY total DESC) AS row_numberFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start+ (SELECT sum(total) AS count,+ breakdown_value AS breakdown_valueFROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- day_start)- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ breakdown_value AS breakdown_value+ FROM+ (SELECT any(e__session.`$session_duration`) AS session_duration,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY e.`$session_id`,+ breakdown_value)+ GROUP BY breakdown_value)+ GROUP BY breakdown_value+ ORDER BY breakdown_value ASC)+ ORDER BY total DESC,+ breakdown_value ASC)+ WHERE isNotNull(breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC,+ breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7705,35 +3441,60 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math.1+# name: TestTrends.test_trends_person_breakdown_with_session_property_single_aggregate_math_and_breakdown.1'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT sum(total) AS total,+ arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 26), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_valueFROM- (SELECT sum(total) AS count,- day_start AS day_start+ (SELECT count AS total,+ breakdown_value AS breakdown_value,+ row_number() OVER (+ ORDER BY total DESC) AS row_numberFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start+ (SELECT sum(total) AS count,+ [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_valueFROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- day_start)- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ breakdown_value_1 AS breakdown_value_1+ FROM+ (SELECT any(e__session.`$session_duration`) AS session_duration,+ ifNull(nullIf(leftUTF8(toString(e__person.`properties___$some_prop`), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY e.`$session_id`,+ breakdown_value_1)+ GROUP BY breakdown_value_1)+ GROUP BY breakdown_value_1+ ORDER BY breakdown_value ASC)+ ORDER BY total DESC,+ breakdown_value ASC)+ WHERE arrayExists(x -> isNotNull(x), breakdown_value)+ GROUP BY breakdown_value+ ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC,+ breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7748,31 +3509,19 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math[new_events_schema.1]+# name: TestTrends.test_trends_with_hogql_math'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM(SELECT sum(total) AS count,day_start AS day_startFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- day_start)+ (SELECT ifNull(accurateCastOrNull(plus(avg(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'x'), ''), 'null'), '^"|"$', ''), 'Float64')), 1000), 'Float64'), 0) AS total,+ toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -7791,35 +3540,21 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math[new_events_schema]+# name: TestTrends.test_trends_with_session_property_single_aggregate_math'''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total+ SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS totalFROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- day_start)- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC+ (SELECT any(e__session.`$session_duration`) AS session_duration+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY e.`$session_id`+ ORDER BY 1 DESC)LIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7834,52 +3569,21 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns+# name: TestTrends.test_trends_with_session_property_single_aggregate_math.1'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS totalFROM- (SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- breakdown_value,- day_start)- GROUP BY breakdown_value,- day_start)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ (SELECT any(e__session.`$session_duration`) AS session_duration+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY e.`$session_id`+ ORDER BY 1 DESC)LIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7894,52 +3598,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.1+# name: TestTrends.test_trends_with_session_property_total_volume_math'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value+ (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ day_start AS day_startFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- breakdown_value,- day_start)- GROUP BY breakdown_value,+ (SELECT any(e__session.`$session_duration`) AS session_duration,+ toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ e.`$session_id`,day_start)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7954,52 +3641,35 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.2+# name: TestTrends.test_trends_with_session_property_total_volume_math.1'''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT sum(total) AS count,- day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value+ (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,+ day_start AS day_startFROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- breakdown_value_1,- day_start)- GROUP BY breakdown_value_1,+ (SELECT any(e__session.`$session_duration`) AS session_duration,+ toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ FROM events AS e+ LEFT JOIN+ (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,+ raw_sessions.session_id_v7 AS session_id_v7+ FROM raw_sessions+ WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))+ GROUP BY day_start,+ e.`$session_id`,day_start)- GROUP BY day_start,- breakdown_value_1- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)- GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ GROUP BY day_start)+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -8014,13 +3684,13 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.3+# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- arrayMap(i -> if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value+ if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_valueFROM- (SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ (SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,breakdown_value AS breakdown_value,@@ -8028,15 +3698,15 @@FROM(SELECT sum(total) AS count,day_start AS day_start,- [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value+ breakdown_value AS breakdown_valueFROM(SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value_1 AS breakdown_value_1,+ breakdown_value AS breakdown_value,day_start AS day_startFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,- toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,+ toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_startFROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,@@ -8047,19 +3717,19 @@WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))GROUP BY day_start,e.`$session_id`,- breakdown_value_1,+ breakdown_value,day_start)- GROUP BY breakdown_value_1,+ GROUP BY breakdown_value,day_start)GROUP BY day_start,- breakdown_value_1+ breakdown_valueORDER BY day_start ASC,breakdown_value ASC)GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE arrayExists(x -> isNotNull(x), breakdown_value)+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)+ WHERE isNotNull(breakdown_value)GROUP BY breakdown_value- ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC+ ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -8074,7 +3744,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns[new_events_schema.1]+# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.1'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -8095,9 +3765,9 @@day_start AS day_startFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7@@ -8134,7 +3804,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns[new_events_schema.2]+# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.2'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -8155,9 +3825,9 @@day_start AS day_startFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7@@ -8194,7 +3864,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns[new_events_schema.3]+# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns.3'''SELECT groupArray(1)(date)[1] AS date,arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,@@ -8215,9 +3885,9 @@day_start AS day_startFROM(SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,+ ifNull(nullIf(leftUTF8(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start- FROM events_json AS e+ FROM events AS eLEFT JOIN(SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,raw_sessions.session_id_v7 AS session_id_v7@@ -8254,263 +3924,36 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_trends_with_session_property_total_volume_math_with_breakdowns[new_events_schema]- '''- SELECT groupArray(1)(date)[1] AS date,- arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total,- if(ifNull(greaterOrEquals(row_number, 25), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value- FROM- (SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total,- breakdown_value AS breakdown_value,- rowNumberInAllBlocks() AS row_number- FROM- (SELECT sum(total) AS count,- day_start AS day_start,- breakdown_value AS breakdown_value- FROM- (SELECT ifNull(quantile(0.5)(accurateCastOrNull(session_duration, 'Float64')), 0) AS total,- breakdown_value AS breakdown_value,- day_start AS day_start- FROM- (SELECT any(e__session.`$session_duration`) AS session_duration,- ifNull(nullIf(leftUTF8(toString(if(notEquals(toJSONString(e.properties.^`$some_property`), '{}'), toJSONString(e.properties.^`$some_property`), if(isNull(e.properties.`$some_property`), NULL, if(startsWith(dynamicType(e.properties.`$some_property`), 'DateTime'), replaceOne(toString(e.properties.`$some_property`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$some_property`), 'Array'), startsWith(dynamicType(e.properties.`$some_property`), 'Map'), startsWith(dynamicType(e.properties.`$some_property`), 'Tuple')), toJSONString(e.properties.`$some_property`), toString(e.properties.`$some_property`)))))), 400), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e- LEFT JOIN- (SELECT dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'UTC')), max(toTimeZone(raw_sessions.max_timestamp, 'UTC'))) AS `$session_duration`,- raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 99999), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC')), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.`$session_id_uuid`, e__session.session_id_v7)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-28 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-04 23:59:59', 'UTC'))), equals(e.event, 'sign up'))- GROUP BY day_start,- e.`$session_id`,- breakdown_value,- day_start)- GROUP BY breakdown_value,- day_start)- GROUP BY day_start,- breakdown_value- ORDER BY day_start ASC,- breakdown_value ASC)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC)- WHERE isNotNull(breakdown_value)- GROUP BY breakdown_value- ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_weekly_active_groups_daily'''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.`$group_0` AS actor_id- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'viewed video'), notEquals(e.`$group_0`, '')), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_weekly_active_groups_daily[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- e.`$group_0` AS actor_id- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'viewed video'), notEquals(e.`$group_0`, '')), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_weekly_active_users_aggregated_range_narrower_than_week- '''- SELECT count(DISTINCT actor_id) AS total- FROM- (SELECT d.timestamp AS timestamp,- e.actor_id AS actor_id- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp,- e.actor_id- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_weekly_active_users_aggregated_range_narrower_than_week[new_events_schema]- '''- SELECT count(DISTINCT actor_id) AS total- FROM- (SELECT d.timestamp AS timestamp,- e.actor_id AS actor_id- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp,- e.actor_id- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week- '''- SELECT count(DISTINCT actor_id) AS total+ SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,+ arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)+ and isNull(_match_date)), _days_for_count), _index), 1))), date) AS totalFROM- (SELECT d.timestamp AS timestamp,- e.actor_id AS actor_id+ (SELECT sum(total) AS count,+ day_start AS day_startFROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp,- e.actor_id- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC'))))+ (SELECT counts AS total,+ toStartOfDay(timestamp) AS day_start+ FROM+ (SELECT d.timestamp AS timestamp,+ count(DISTINCT e.actor_id) AS counts+ FROM+ (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,+ e.`$group_0` AS actor_id+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(equals(e.event, 'viewed video'), notEquals(e.`$group_0`, '')), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC'))))+ GROUP BY timestamp, actor_id) AS e+ CROSS JOIN+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))) AS numbers) AS d+ WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))+ GROUP BY d.timestamp+ ORDER BY d.timestamp ASC)+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))))+ GROUP BY day_start+ ORDER BY day_start ASC)+ ORDER BY arraySum(total) DESCLIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -8525,7 +3968,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week[new_events_schema]+# name: TestTrends.test_weekly_active_users_aggregated_range_narrower_than_week'''SELECT count(DISTINCT actor_id) AS totalFROM@@ -8534,7 +3977,7 @@FROM(SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -8542,16 +3985,16 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC'))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))GROUP BY timestamp, actor_id) AS eCROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')))) AS numbers) AS d+ (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp+ FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))) AS numbers) AS dWHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))GROUP BY d.timestamp,e.actor_idORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC'))))+ WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-11 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))LIMIT 50000 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -8566,7 +4009,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week_with_sampling+# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week'''SELECT count(DISTINCT actor_id) AS totalFROM@@ -8607,7 +4050,7 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week_with_sampling[new_events_schema]+# name: TestTrends.test_weekly_active_users_aggregated_range_wider_than_week_with_sampling'''SELECT count(DISTINCT actor_id) AS totalFROM@@ -8616,7 +4059,7 @@FROM(SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -8699,57 +4142,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_daily[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-19 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_weekly_active_users_filtering'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,@@ -8811,67 +4203,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_filtering[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfDay(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(equals(e.event, '$pageview'), in(e__person.properties___name, tuple('person-1', 'person-2'))), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')), toIntervalDay(1)), toIntervalDay(numbers.number)) AS timestamp- FROM numbers(dateDiff('day', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-12 23:59:59', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_weekly_active_users_hourly'''SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC')), toIntervalHour(1)))), 1))) AS date,@@ -8923,57 +4254,6 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_hourly[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(number)), range(0, plus(coalesce(dateDiff('hour', toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1)), toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC')), toIntervalHour(1)))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT counts AS total,- toStartOfHour(timestamp) AS day_start- FROM- (SELECT d.timestamp AS timestamp,- count(DISTINCT e.actor_id) AS counts- FROM- (SELECT toStartOfHour(toTimeZone(e.timestamp, 'UTC')) AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$pageview'), greaterOrEquals(timestamp, minus(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalDay(7))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC'))))- GROUP BY timestamp, actor_id) AS e- CROSS JOIN- (SELECT minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC')), toIntervalHour(1)), toIntervalHour(numbers.number)) AS timestamp- FROM numbers(dateDiff('hour', minus(toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1)), toIntervalDay(7)), assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC')))) AS numbers) AS d- WHERE and(lessOrEquals(e.timestamp, d.timestamp), greater(e.timestamp, minus(d.timestamp, toIntervalDay(7))))- GROUP BY d.timestamp- ORDER BY d.timestamp ASC)- WHERE and(greaterOrEquals(timestamp, toStartOfInterval(assumeNotNull(toDateTime('2020-01-09 06:00:00', 'UTC')), toIntervalHour(1))), lessOrEquals(timestamp, assumeNotNull(toDateTime('2020-01-09 17:00:00', 'UTC')))))- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTrends.test_weekly_active_users_weekly'''SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), 0))), 1))) AS date,@@ -9012,41 +4292,3 @@use_hive_partitioning=0'''# ----# name: TestTrends.test_weekly_active_users_weekly[new_events_schema]- '''- SELECT arrayMap(number -> plus(toStartOfWeek(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), 0), toIntervalWeek(number)), range(0, plus(coalesce(dateDiff('week', toStartOfWeek(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), 0), toStartOfWeek(assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC')), 0))), 1))) AS date,- arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)- and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total- FROM- (SELECT sum(total) AS count,- day_start AS day_start- FROM- (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total,- toStartOfWeek(toTimeZone(e.timestamp, 'UTC'), 0) AS day_start- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) 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 equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2019-12-29 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2020-01-18 23:59:59', 'UTC'))), equals(e.event, '$pageview'))- GROUP BY day_start)- GROUP BY day_start- ORDER BY day_start ASC)- ORDER BY arraySum(total) DESC- LIMIT 50000 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,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/products/revenue_analytics/backend/api.py b/products/revenue_analytics/backend/api.pyindex c5bd10447ec1..6b992e303d90 100644--- a/products/revenue_analytics/backend/api.py+++ b/products/revenue_analytics/backend/api.py@@ -3,6 +3,7 @@ from typing import castfrom posthoganalytics import capture_exceptionfrom rest_framework import serializers, statusfrom rest_framework.decorators import action+from rest_framework.exceptions import PermissionDeniedfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.request import Requestfrom rest_framework.response import Response@@ -19,6 +20,7 @@ from posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.clickhouse.query_tagging import Feature, tag_queriesfrom posthog.models.team.team import Teamfrom posthog.models.user import User+from posthog.rbac.user_access_control import AccessControlLevelResource, UserAccessControlfrom products.revenue_analytics.backend.joins import ensure_person_join_for_team, remove_person_join_for_teamfrom products.revenue_analytics.backend.views import RevenueAnalyticsBaseView@@ -76,6 +78,13 @@ def find_values_for_revenue_analytics_property(key: str, team: Team, user: User)return values+# `scope_object = "INTERNAL"` opts these viewsets out of the framework's resource-level+# access-control check, so enforce `revenue_analytics` access here to match the query runners.+def _assert_revenue_analytics_access(team: Team, user: User, required_level: AccessControlLevelResource) -> None:+ if not UserAccessControl(user=user, team=team).check_access_level_for_resource("revenue_analytics", required_level):+ raise PermissionDenied("You don't have access to revenue analytics in this project.")++class RevenueAnalyticsTaxonomyViewSet(TeamAndOrgViewSetMixin, GenericViewSet):scope_object = "INTERNAL"serializer_class = _FallbackSerializer@@ -83,6 +92,8 @@ class RevenueAnalyticsTaxonomyViewSet(TeamAndOrgViewSetMixin, GenericViewSet):@action(methods=["GET"], detail=False)def values(self, request: Request, **kwargs):+ _assert_revenue_analytics_access(self.team, cast(User, request.user), "viewer")+key = request.GET.get("key")if key is None:return Response({"results": [], "refreshing": False})@@ -101,6 +112,8 @@ class RevenueAnalyticsJoinViewSet(TeamAndOrgViewSetMixin, GenericViewSet):permission_classes = [IsAuthenticated]def create(self, request: Request, **kwargs):+ _assert_revenue_analytics_access(self.team, cast(User, request.user), "editor")+serializer = RevenueAnalyticsJoinSerializer(data=request.data)serializer.is_valid(raise_exception=True)diff --git a/products/revenue_analytics/backend/test/test_api_access_control.py b/products/revenue_analytics/backend/test/test_api_access_control.pynew file mode 100644index 000000000000..75169d10531e--- /dev/null+++ b/products/revenue_analytics/backend/test/test_api_access_control.py@@ -0,0 +1,64 @@+import pytest+from posthog.test.base import APIBaseTest+from unittest.mock import patch++from rest_framework import status++from posthog.constants import AvailableFeature+from posthog.models.organization import OrganizationMembership+from posthog.models.user import User++AccessControl = pytest.importorskip("ee.models.rbac.access_control").AccessControl++pytestmark = [pytest.mark.django_db]++_HELPER = "products.revenue_analytics.backend.api.find_values_for_revenue_analytics_property"+++class TestRevenueAnalyticsAPIAccessControl(APIBaseTest):+ def setUp(self):+ super().setUp()+ self.taxonomy_url = f"/api/environments/{self.team.pk}/revenue_analytics/taxonomy/values/"+ self.joins_url = f"/api/environments/{self.team.pk}/revenue_analytics/joins/"+ self.organization.available_product_features = [+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL}+ ]+ self.organization.save()++ def _member(self, revenue_analytics_level: str) -> User:+ member = User.objects.create_and_join(+ self.organization, f"member-{revenue_analytics_level}@posthog.com", "testtest"+ )+ membership = OrganizationMembership.objects.get(user=member, organization=self.organization)+ AccessControl.objects.create(+ team=self.team,+ resource="revenue_analytics",+ access_level=revenue_analytics_level,+ organization_member=membership,+ )+ return member++ @patch(_HELPER, return_value=["[email protected]"])+ def test_member_denied_revenue_analytics_access_cannot_read_taxonomy_values(self, _mock):+ self.client.force_login(self._member("none"))+ response = self.client.get(self.taxonomy_url, data={"key": "revenue_analytics_customer.email"})+ assert response.status_code == status.HTTP_403_FORBIDDEN++ @patch(_HELPER, return_value=["[email protected]"])+ def test_member_with_viewer_access_can_read_taxonomy_values(self, _mock):+ self.client.force_login(self._member("viewer"))+ response = self.client.get(self.taxonomy_url, data={"key": "revenue_analytics_customer.email"})+ assert response.status_code == status.HTTP_200_OK+ assert response.json()["results"] == [{"name": "[email protected]"}]++ def test_member_denied_revenue_analytics_access_cannot_change_joins(self):+ self.client.force_login(self._member("none"))+ response = self.client.post(self.joins_url, data={"enabled": True})+ assert response.status_code == status.HTTP_403_FORBIDDEN++ def test_viewer_access_cannot_change_joins(self):+ # Joins mutate person-join config, so writing requires editor; viewer-only must be blocked.+ self.client.force_login(self._member("viewer"))+ response = self.client.post(self.joins_url, data={"enabled": True})+ assert response.status_code == status.HTTP_403_FORBIDDEN