Skip to content

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

feat(retention): wire customAggregationTarget for data warehouse entities (#85438)

Thomas Obermüllerfad99eefd3fd
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.test.ts b/frontend/src/scenes/insights/insightVizDataLogic.test.ts
index 2c8929e09684..e859e8936cca 100644
--- a/frontend/src/scenes/insights/insightVizDataLogic.test.ts
+++ b/frontend/src/scenes/insights/insightVizDataLogic.test.ts
@@ -8,7 +8,14 @@ import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { useMocks } from '~/mocks/jest'
import { LATEST_VERSIONS } from '~/queries/latest-versions'
import { funnelsQueryDefault, trendsQueryDefault } from '~/queries/nodes/InsightQuery/defaults'
-import { FunnelsQuery, LifecycleQuery, Node, NodeKind, TrendsQuery } from '~/queries/schema/schema-general'
+import {
+ FunnelsQuery,
+ LifecycleQuery,
+ Node,
+ NodeKind,
+ RetentionQuery,
+ TrendsQuery,
+} from '~/queries/schema/schema-general'
import { setLatestVersionsOnQuery } from '~/queries/utils'
import { initKeaTests } from '~/test/init'
import {
@@ -226,6 +233,42 @@ describe('insightVizDataLogic', () => {
})
})
+ it('clears a custom retention aggregation target when an entity switches away from the data warehouse', () => {
+ const dataWarehouseEntity = {
+ id: 'warehouse_orders',
+ type: 'data_warehouse' as const,
+ table_name: 'warehouse_orders',
+ timestamp_field: 'created_at',
+ aggregation_target_field: 'order_id',
+ }
+
+ builtInsightVizDataLogic.actions.updateQuerySource({
+ kind: NodeKind.RetentionQuery,
+ retentionFilter: {
+ customAggregationTarget: true,
+ targetEntity: dataWarehouseEntity,
+ returningEntity: dataWarehouseEntity,
+ },
+ } as RetentionQuery)
+ expect(builtInsightVizDataLogic.values.retentionFilter).toMatchObject({ customAggregationTarget: true })
+
+ // updateInsightFilter merges entity changes into the full filter, so the stale flag rides along
+ builtInsightVizDataLogic.actions.updateQuerySource({
+ kind: NodeKind.RetentionQuery,
+ retentionFilter: {
+ customAggregationTarget: true,
+ targetEntity: { id: '$pageview', type: 'events' },
+ returningEntity: dataWarehouseEntity,
+ },
+ } as RetentionQuery)
+
+ expect(builtInsightVizDataLogic.values.retentionFilter).toEqual({
+ customAggregationTarget: undefined,
+ targetEntity: { id: '$pageview', type: 'events' },
+ returningEntity: dataWarehouseEntity,
+ })
+ })
+
it('clears unsupported lifecycle globals when switching to a data warehouse series', () => {
const lifecycleQuery: LifecycleQuery = {
kind: NodeKind.LifecycleQuery,
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.ts
index 8924394d4072..80b66f51a135 100644
--- a/frontend/src/scenes/insights/insightVizDataLogic.ts
+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts
@@ -2887,6 +2887,22 @@ const handleQuerySourceUpdateSideEffects = (
;(mergedUpdate as LifecycleQuery).samplingFactor = undefined
}
+ // Switching a retention entity away from the data warehouse invalidates the "Custom entities"
+ // aggregation target, which the backend rejects for non-warehouse entities.
+ if (isRetentionQuery(currentState) && maybeChangedInsightFilter) {
+ const nextRetentionFilter = maybeChangedInsightFilter as RetentionFilter
+ if (
+ nextRetentionFilter.customAggregationTarget &&
+ (nextRetentionFilter.targetEntity?.type !== 'data_warehouse' ||
+ nextRetentionFilter.returningEntity?.type !== 'data_warehouse')
+ ) {
+ ;(mergedUpdate as RetentionQuery).retentionFilter = {
+ ...nextRetentionFilter,
+ customAggregationTarget: undefined,
+ }
+ }
+ }
+
// We do not support properties, filtering test accounts, and sampling for DWH nodes
// Disable them if there are any
if (
diff --git a/frontend/src/scenes/retention/RetentionModal.tsx b/frontend/src/scenes/retention/RetentionModal.tsx
index b7dae7a0f760..171b07adeb73 100644
--- a/frontend/src/scenes/retention/RetentionModal.tsx
+++ b/frontend/src/scenes/retention/RetentionModal.tsx
@@ -33,6 +33,7 @@ export function RetentionModal(): JSX.Element | null {
const { loadMorePeople } = useActions(retentionPeopleLogic(insightProps))
const {
aggregationTargetLabel,
+ canOpenPersonModal,
selectedInterval,
selectedBreakdownValue,
selectedRow: row,
@@ -61,7 +62,7 @@ export function RetentionModal(): JSX.Element | null {
}
: undefined
- if (selectedInterval === null || !row) {
+ if (!canOpenPersonModal || selectedInterval === null || !row) {
return null
}
diff --git a/frontend/src/scenes/retention/RetentionTable.tsx b/frontend/src/scenes/retention/RetentionTable.tsx
index 0f7836cfb158..80d2618b93bc 100644
--- a/frontend/src/scenes/retention/RetentionTable.tsx
+++ b/frontend/src/scenes/retention/RetentionTable.tsx
@@ -42,6 +42,7 @@ export function RetentionTable({
const { hoveredColumn } = useValues(retentionTableLogic(insightProps))
const { updateInsightFilter } = useActions(retentionLogic(insightProps))
const { openModal } = useActions(retentionModalLogic(insightProps))
+ const { canOpenPersonModal } = useValues(retentionModalLogic(insightProps))
const selectedInterval = retentionFilter?.selectedInterval ?? null
const allowSelectingColumns = !inSharedMode && !embedded
@@ -175,7 +176,7 @@ export function RetentionTable({
<tr
key={rowIndex}
onClick={() => {
- if (!inSharedMode) {
+ if (!inSharedMode && canOpenPersonModal) {
openModal(
rowIndex,
breakdownValue === NO_BREAKDOWN_VALUE ? null : breakdownValue
@@ -203,7 +204,7 @@ export function RetentionTable({
// Open the modal for this cohort and tell it which
// interval column was clicked so it can highlight it.
e.stopPropagation()
- if (!inSharedMode) {
+ if (!inSharedMode && canOpenPersonModal) {
openModal(
rowIndex,
breakdownValue === NO_BREAKDOWN_VALUE
@@ -228,7 +229,7 @@ export function RetentionTable({
? (column.aggregation_value ?? 0)
: undefined
}
- clickable={true}
+ clickable={canOpenPersonModal}
isCurrentPeriod={column.isCurrentPeriod}
backgroundColor={backgroundColor}
/>
diff --git a/frontend/src/scenes/retention/retentionModalLogic.test.ts b/frontend/src/scenes/retention/retentionModalLogic.test.ts
index 10ce7800c378..2dc00d3a6bab 100644
--- a/frontend/src/scenes/retention/retentionModalLogic.test.ts
+++ b/frontend/src/scenes/retention/retentionModalLogic.test.ts
@@ -1,5 +1,6 @@
import { expectLogic } from 'kea-test-utils'
+import { AGGREGATION_LABEL_FOR_CUSTOM_DATA_WAREHOUSE } from 'scenes/insights/filters/aggregationTargetUtils'
import { teamLogic } from 'scenes/teamLogic'
import { useMocks } from '~/mocks/jest'
@@ -24,6 +25,24 @@ const retentionQuery: RetentionQuery = {
},
}
+const dataWarehouseEntity = {
+ id: 'warehouse_orders',
+ type: 'data_warehouse' as const,
+ table_name: 'warehouse_orders',
+ timestamp_field: 'created_at',
+ aggregation_target_field: 'order_id',
+}
+
+const dataWarehouseQuery: RetentionQuery = {
+ kind: NodeKind.RetentionQuery,
+ retentionFilter: {
+ period: RetentionPeriod.Day,
+ targetEntity: dataWarehouseEntity,
+ returningEntity: dataWarehouseEntity,
+ customAggregationTarget: true,
+ },
+}
+
const cohortRow = (
label: string,
count: number,
@@ -188,4 +207,44 @@ describe('retentionModalLogic', () => {
expect(logic.values.selectedInterval).toBeNull()
expect(logic.values.selectedRow).toBeNull()
})
+
+ it('disables the person modal and relabels actors for a custom aggregation target', async () => {
+ await expectLogic(logic, () => {
+ retentionLogic(insightProps).actions.updateQuerySource(dataWarehouseQuery)
+ }).toMatchValues({
+ canOpenPersonModal: false,
+ aggregationTargetLabel: AGGREGATION_LABEL_FOR_CUSTOM_DATA_WAREHOUSE,
+ })
+
+ // Backstop: even when a render surface dispatches openModal anyway, no actors query fires
+ await expectLogic(logic, () => {
+ logic.actions.openModal(0)
+ }).toNotHaveDispatchedActions(['loadPeople'])
+
+ await expectLogic(logic, () => {
+ retentionLogic(insightProps).actions.updateQuerySource(retentionQuery)
+ }).toMatchValues({
+ canOpenPersonModal: true,
+ })
+
+ await expectLogic(logic, () => {
+ logic.actions.openModal(0)
+ }).toDispatchActions(['loadPeople'])
+ })
+
+ it('closes an open modal when the aggregation target becomes custom', async () => {
+ await loadResults(fourCohorts)
+ await expectLogic(logic, () => {
+ logic.actions.openModal(1)
+ }).toFinishAllListeners()
+ expect(logic.values.selectedRow?.values[0].count).toBe(90)
+
+ await expectLogic(logic, () => {
+ retentionLogic(insightProps).actions.updateQuerySource(dataWarehouseQuery)
+ }).toFinishAllListeners()
+
+ // Cleared, not just hidden: switching back must not restore the old cohort
+ expect(logic.values.selectedInterval).toBeNull()
+ expect(logic.values.selectedRow).toBeNull()
+ })
})
diff --git a/frontend/src/scenes/retention/retentionModalLogic.ts b/frontend/src/scenes/retention/retentionModalLogic.ts
index 63e0048a025c..381aee6c362c 100644
--- a/frontend/src/scenes/retention/retentionModalLogic.ts
+++ b/frontend/src/scenes/retention/retentionModalLogic.ts
@@ -6,6 +6,7 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { AGGREGATION_LABEL_FOR_CUSTOM_DATA_WAREHOUSE } from 'scenes/insights/filters/aggregationTargetUtils'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { retentionToActorsQuery } from 'scenes/retention/queries'
@@ -62,6 +63,7 @@ export interface retentionModalLogicValues {
results: ProcessedRetentionPayload[] // retentionLogic
actorsQuery: ActorsQuery | null
aggregationTargetLabel: Noun
+ canOpenPersonModal: boolean
exploreUrl: string | null
insightEventsQueryUrl: string | null
isCohortModalOpen: boolean
@@ -116,8 +118,10 @@ export interface retentionModalLogicMeta {
| WebOverviewQuery
| WebStatsTableQuery
| null,
+ retentionFilter: RetentionFilter | null,
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun
) => Noun
+ canOpenPersonModal: (retentionFilter: RetentionFilter | null) => boolean
actorsQuery: (
querySource:
| FunnelsQuery
@@ -211,7 +215,7 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
}),
selectors({
aggregationTargetLabel: [
- (s) => [s.querySource, s.aggregationLabel],
+ (s) => [s.querySource, s.retentionFilter, s.aggregationLabel],
(
querySource:
| RetentionQuery
@@ -223,8 +227,12 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
| import('~/queries/schema/schema-general').TrendsQuery
| import('~/queries/schema/schema-general').WebOverviewQuery
| import('~/queries/schema/schema-general').WebStatsTableQuery,
+ retentionFilter: RetentionFilter | null,
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun
): Noun => {
+ if (retentionFilter?.customAggregationTarget) {
+ return AGGREGATION_LABEL_FOR_CUSTOM_DATA_WAREHOUSE
+ }
const aggregation_group_type_index =
isLifecycleQuery(querySource) || isStickinessQuery(querySource)
? undefined
@@ -232,6 +240,10 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
return aggregationLabel(aggregation_group_type_index)
},
],
+ canOpenPersonModal: [
+ (s) => [s.retentionFilter],
+ (retentionFilter: RetentionFilter | null): boolean => !retentionFilter?.customAggregationTarget,
+ ],
actorsQuery: [
(s) => [s.querySource, s.selectedInterval, s.selectedBreakdownValue],
(
@@ -331,9 +343,21 @@ export const retentionModalLogic = kea<retentionModalLogicType>([
actions.closeModal()
}
},
+ // Drop the selection rather than just hiding the modal, so switching the target back
+ // can't restore a cohort whose actors were never loaded.
+ canOpenPersonModal: (canOpenPersonModal: boolean) => {
+ if (!canOpenPersonModal && values.selectedInterval !== null) {
+ actions.closeModal()
+ }
+ },
})),
listeners(({ actions, values }) => ({
openModal: ({ rowIndex, breakdownValue }: { rowIndex: number; breakdownValue?: string | number | null }) => {
+ // Backstop for render surfaces that don't check canOpenPersonModal before dispatching:
+ // custom aggregation targets can't resolve actors, so don't fire the query.
+ if (!values.canOpenPersonModal) {
+ return
+ }
actions.loadPeople(rowIndex, breakdownValue)
},
saveAsCohort: async ({ cohortName }) => {
diff --git a/posthog/api/test/__snapshots__/test_event.ambr b/posthog/api/test/__snapshots__/test_event.ambr
index d8fce39e8eb5..60c0303ea3b0 100644
--- a/posthog/api/test/__snapshots__/test_event.ambr
+++ b/posthog/api/test/__snapshots__/test_event.ambr
@@ -145,326 +145,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEvents.test_event_property_values.7
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'random_prop'), ''), 'null'), '^"|"$', '') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'random_prop'), ''), 'null'), '^"|"$', '')), equals(events.event, '404_i_dont_exist'), ifNull(ilike(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'random_prop'), ''), 'null'), '^"|"$', '')), '%qw%'), 0))
- ORDER BY length(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'random_prop'), ''), 'null'), '^"|"$', ''))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.1]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%qw%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.2]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%QW%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.3]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%6%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.4]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), equals(events.event, 'random event'), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%6%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.5]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), or(equals(events.event, 'foo'), equals(events.event, 'random event')), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%6%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.6]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), equals(events.event, '404_i_dont_exist'), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%qw%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema.7]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), equals(events.event, '404_i_dont_exist'), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))), '%qw%'), 0))
- ORDER BY length(toString(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop))))))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values[new_events_schema]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.random_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.random_prop)))) AS `if(notEquals(toJSONString(properties.^random_prop), '{}'), toJSONString(properties.^random_prop), if(isNull(properties.random_prop), NULL, if(startsWith(dynamicType(properties.random_prop), 'DateTime'), concat('"', replaceOne(toString(properties.random_prop), ' ', 'T'), '"'), toJSONString(properties.random_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^random_prop), '{}'), toJSONString(events.properties.^random_prop), if(isNull(events.properties.random_prop), NULL, if(startsWith(dynamicType(events.properties.random_prop), 'DateTime'), replaceOne(toString(events.properties.random_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_prop), 'Array'), startsWith(dynamicType(events.properties.random_prop), 'Map'), startsWith(dynamicType(events.properties.random_prop), 'Tuple')), toJSONString(events.properties.random_prop), toString(events.properties.random_prop)))))))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values_materialized
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.1
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), ilike(events.mat_random_prop, '%qw%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.2
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), ilike(events.mat_random_prop, '%QW%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.3
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), ilike(events.mat_random_prop, '%6%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.4
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), equals(events.event, 'random event'), ilike(events.mat_random_prop, '%6%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.5
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), or(equals(events.event, 'foo'), equals(events.event, 'random event')), ilike(events.mat_random_prop, '%6%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEvents.test_event_property_values_materialized.6
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_random_prop, ''), 'null') AS random_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_random_prop, ''), 'null')), equals(events.event, '404_i_dont_exist'), ilike(events.mat_random_prop, '%qw%'))
- ORDER BY length(toString(nullIf(nullIf(events.mat_random_prop, ''), 'null'))) ASC
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEvents.test_event_property_values_with_hidden_properties
'''
/* user_id:0 request:_snapshot_ */
@@ -485,44 +165,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEvents.test_event_property_values_with_hidden_properties[new_events_schema]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^visible_prop), '{}'), toJSONString(events.properties.^visible_prop), if(isNull(events.properties.visible_prop), NULL, if(startsWith(dynamicType(events.properties.visible_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.visible_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.visible_prop)))) AS `if(notEquals(toJSONString(properties.^visible_prop), '{}'), toJSONString(properties.^visible_prop), if(isNull(properties.visible_prop), NULL, if(startsWith(dynamicType(properties.visible_prop), 'DateTime'), concat('"', replaceOne(toString(properties.visible_prop), ' ', 'T'), '"'), toJSONString(properties.visible_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^visible_prop), '{}'), toJSONString(events.properties.^visible_prop), if(isNull(events.properties.visible_prop), NULL, if(startsWith(dynamicType(events.properties.visible_prop), 'DateTime'), replaceOne(toString(events.properties.visible_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.visible_prop), 'Array'), startsWith(dynamicType(events.properties.visible_prop), 'Map'), startsWith(dynamicType(events.properties.visible_prop), 'Tuple')), toJSONString(events.properties.visible_prop), toString(events.properties.visible_prop)))))))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values_with_hidden_properties_materialized
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_visible_prop, ''), 'null') AS visible_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_visible_prop, ''), 'null')))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEvents.test_event_property_values_without_hidden_properties
'''
/* user_id:0 request:_snapshot_ */
@@ -543,41 +185,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEvents.test_event_property_values_without_hidden_properties[new_events_schema]
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.test_prop), ' ', 'T')), ''), '"'), toJSONString(events.properties.test_prop)))) AS `if(notEquals(toJSONString(properties.^test_prop), '{}'), toJSONString(properties.^test_prop), if(isNull(properties.test_prop), NULL, if(startsWith(dynamicType(properties.test_prop), 'DateTime'), concat('"', replaceOne(toString(properties.test_prop), ' ', 'T'), '"'), toJSONString(properties.test_prop))))`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestEvents.test_event_property_values_without_hidden_properties_materialized
- '''
- /* user_id:0 request:_snapshot_ */
- SELECT DISTINCT nullIf(nullIf(events.mat_test_prop, ''), 'null') AS test_prop
- FROM events
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, toDateTime64('2020-01-13 00:00:00', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-20 23:59:59', 6, 'UTC')), isNotNull(nullIf(nullIf(events.mat_test_prop, ''), 'null')))
- LIMIT 10 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr
index 11dbb51b9d03..e54171078622 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr
@@ -218,177 +218,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelCorrelationActors.test_funnel_correlation_on_event_with_recordings[new_events_schema.1]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (WITH funnel_actors AS
- (SELECT aggregation_target AS actor_id,
- matched_events_array[plus(step_reached, 1)] AS matching_events,
- (matched_events_array[1][1]).1 AS timestamp,
- nullIf((matched_events_array[3][1]).1, 0) AS final_timestamp,
- (matched_events_array[1][1]).1 AS first_timestamp,
- steps AS steps
- 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '$pageview'), 1, 0) AS step_0,
- if(equals(e.event, 'insight analyzed'), 1, 0) AS step_1,
- if(equals(e.event, 'insight updated'), 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('$pageview', 'insight analyzed', 'insight updated'))), 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 bitTest(steps_bitfield, 0)
- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),
- assumeNotNull(toDateTime('2021-01-01 00:00:00', 'UTC')) AS date_from,
- assumeNotNull(toDateTime('2021-01-08 23:59:59', 'UTC')) AS date_to,
- 3 AS target_step,
- ['$pageview', 'insight analyzed', 'insight updated'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,
- any(funnel_actors.matching_events) AS matching_events,
- actor_id AS id
- FROM events_json AS event
- 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 event__override ON equals(event.distinct_id, event__override.distinct_id)
- JOIN funnel_actors ON equals(if(not(empty(event__override.distinct_id)), event__override.person_id, event.person_id), funnel_actors.actor_id)
- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'insight loaded'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)
- or isNotNull(target_step)))
- GROUP BY actor_id
- ORDER BY actor_id ASC) 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: TestFunnelCorrelationActors.test_funnel_correlation_on_event_with_recordings[new_events_schema]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (WITH funnel_actors AS
- (SELECT aggregation_target AS actor_id,
- matched_events_array[plus(step_reached, 1)] AS matching_events,
- (matched_events_array[1][1]).1 AS timestamp,
- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,
- (matched_events_array[1][1]).1 AS first_timestamp,
- steps AS steps
- 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '$pageview'), 1, 0) AS step_0,
- if(equals(e.event, 'insight analyzed'), 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, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed'))), or(equals(step_0, 1), equals(step_1, 1))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE bitTest(steps_bitfield, 0)
- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),
- assumeNotNull(toDateTime('2021-01-01 00:00:00', 'UTC')) AS date_from,
- assumeNotNull(toDateTime('2021-01-08 23:59:59', 'UTC')) AS date_to,
- 2 AS target_step,
- ['$pageview', 'insight analyzed'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,
- any(funnel_actors.matching_events) AS matching_events,
- actor_id AS id
- FROM events_json AS event
- 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 event__override ON equals(event.distinct_id, event__override.distinct_id)
- JOIN funnel_actors ON equals(if(not(empty(event__override.distinct_id)), event__override.person_id, event.person_id), funnel_actors.actor_id)
- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'insight loaded'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)
- and isNull(target_step)))
- GROUP BY actor_id
- ORDER BY actor_id ASC) 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: TestFunnelCorrelationActors.test_funnel_correlation_on_properties_with_recordings
'''
SELECT source.id,
@@ -497,87 +326,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelCorrelationActors.test_funnel_correlation_on_properties_with_recordings[new_events_schema]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (WITH funnel_actors AS
- (SELECT aggregation_target AS actor_id,
- matched_events_array[plus(step_reached, 1)] AS matching_events,
- (matched_events_array[1][1]).1 AS timestamp,
- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,
- (matched_events_array[1][1]).1 AS first_timestamp,
- steps AS steps
- 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '$pageview'), 1, 0) AS step_0,
- if(equals(e.event, 'insight analyzed'), 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)
- LEFT JOIN
- (SELECT person.id AS id,
- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo
- 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(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(equals(step_0, 1), equals(step_1, 1))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE bitTest(steps_bitfield, 0)
- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),
- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,
- any(funnel_actors.matching_events) AS matching_events,
- actor_id AS id
- FROM funnel_actors
- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)
- and isNull(target_step))
- GROUP BY funnel_actors.actor_id
- ORDER BY funnel_actors.actor_id ASC) 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_data_warehouse.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr
index d51ea8913ba5..0408196f04ac 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_data_warehouse.ambr
@@ -143,90 +143,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelDataWarehouse.test_funnels_data_warehouse_and_regular_nodes[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,
- breakdown AS final_prop
- 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 e.timestamp AS timestamp,
- e.aggregation_target AS aggregation_target,
- e.uuid AS uuid,
- e.`$session_id` AS `$session_id`,
- e.`$window_id` AS `$window_id`,
- e.step_0 AS step_0,
- e.step_1 AS step_1
- FROM
- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,
- toString(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,
- 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, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview'))), equals(step_0, 1))
- UNION ALL SELECT toTimeZone(e.created, 'UTC') AS timestamp,
- toString(accurateCastOrNull(e.user_id, 'UUID')) AS aggregation_target,
- tupleElement(tuple(throwIf(isNull(e.uuid), 'Encountered a null value in posthog_test_test_table_1.uuid, but a non-null value is required. Please ensure this column contains no null values, or add a filter to exclude rows with null values.'), toUUIDOrDefault(toString(e.uuid), reinterpretAsUUID(hex(MD5(concat('posthog_test_test_table_1_0_', ifNull(toString(e.uuid), ''))))))), 2) AS uuid,
- NULL AS `$session_id`,
- NULL AS `$window_id`,
- 0 AS step_0,
- if(1, 1, 0) AS step_1
- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e
- WHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)
- 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 100 SETTINGS join_algorithm='auto',
- format_csv_allow_double_quotes=1,
- readonly=2,
- 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: TestFunnelDataWarehouse.test_funnels_data_warehouse_and_regular_nodes_string_aggregation_target
'''
SELECT sum(step_1) AS step_1,
@@ -311,90 +227,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelDataWarehouse.test_funnels_data_warehouse_and_regular_nodes_string_aggregation_target[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,
- breakdown AS final_prop
- 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 e.timestamp AS timestamp,
- e.aggregation_target AS aggregation_target,
- e.uuid AS uuid,
- e.`$session_id` AS `$session_id`,
- e.`$window_id` AS `$window_id`,
- e.step_0 AS step_0,
- e.step_1 AS step_1
- FROM
- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,
- toString(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,
- 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, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview'))), equals(step_0, 1))
- UNION ALL SELECT toTimeZone(e.created, 'UTC') AS timestamp,
- toString(e.user_id) AS aggregation_target,
- tupleElement(tuple(throwIf(isNull(e.uuid), 'Encountered a null value in posthog_test_test_table_1.uuid, but a non-null value is required. Please ensure this column contains no null values, or add a filter to exclude rows with null values.'), toUUIDOrDefault(toString(e.uuid), reinterpretAsUUID(hex(MD5(concat('posthog_test_test_table_1_0_', ifNull(toString(e.uuid), ''))))))), 2) AS uuid,
- NULL AS `$session_id`,
- NULL AS `$window_id`,
- 0 AS step_0,
- if(1, 1, 0) AS step_1
- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e
- WHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)
- 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 100 SETTINGS join_algorithm='auto',
- format_csv_allow_double_quotes=1,
- readonly=2,
- 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: TestFunnelDataWarehouse.test_funnels_data_warehouse_and_regular_nodes_string_aggregation_target_actors
'''
SELECT source.id,
@@ -469,80 +301,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelDataWarehouse.test_funnels_data_warehouse_and_regular_nodes_string_aggregation_target_actors[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'), 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 e.timestamp AS timestamp,
- e.aggregation_target AS aggregation_target,
- e.uuid AS uuid,
- e.`$session_id` AS `$session_id`,
- e.`$window_id` AS `$window_id`,
- e.step_0 AS step_0,
- e.step_1 AS step_1
- FROM
- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,
- toString(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,
- 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, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview'))), equals(step_0, 1))
- UNION ALL SELECT toTimeZone(e.created, 'UTC') AS timestamp,
- toString(e.user_id) AS aggregation_target,
- tupleElement(tuple(throwIf(isNull(e.uuid), 'Encountered a null value in posthog_test_test_table_1.uuid, but a non-null value is required. Please ensure this column contains no null values, or add a filter to exclude rows with null values.'), toUUIDOrDefault(toString(e.uuid), reinterpretAsUUID(hex(MD5(concat('posthog_test_test_table_1_0_', ifNull(toString(e.uuid), ''))))))), 2) AS uuid,
- NULL AS `$session_id`,
- NULL AS `$window_id`,
- 0 AS step_0,
- if(1, 1, 0) AS step_1
- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql_queries.insights.funnels.funnel_data_warehouse/posthog_test_test_table_1/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` Int64, `uuid` String, `created` DateTime64(3, \'UTC\'), `user_id` String, `event_name` String, `id_decimal` Decimal(18, 2), `properties` Nullable(String), `id_with_nulls` Nullable(Int64)') AS e
- WHERE and(and(greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), equals(step_1, 1))) AS e)
- 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
- ORDER BY source.id ASC
- LIMIT 101
- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,
- join_algorithm='auto',
- format_csv_allow_double_quotes=1,
- readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=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: TestFunnelDataWarehouse.test_funnels_data_warehouse_non_uuid_id_column
'''
SELECT sum(step_1) AS step_1,
diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr
index b8f37c293cbe..badfc4d1ab1a 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr
@@ -260,192 +260,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelPersons.test_funnel_person_recordings[new_events_schema.1]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[2] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, '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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE bitTest(steps_bitfield, 1)
- 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: TestFunnelPersons.test_funnel_person_recordings[new_events_schema.2]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[2] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, '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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE and(bitTest(steps_bitfield, 1), not(bitTest(steps_bitfield, 2)))
- 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: TestFunnelPersons.test_funnel_person_recordings[new_events_schema]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[1] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, '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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE bitTest(steps_bitfield, 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_strict.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.ambr
index d6c121c16f80..acaadefd2bf3 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict.ambr
@@ -67,753 +67,26 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelStrictStepsBreakdown.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', 'strict', [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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step
'''
- 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,
- groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,
- arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'strict', 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(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
- [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
- if(equals(step_1, 1), 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)
- WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step[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,
- groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,
- arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'strict', 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,
- if(equals(step_1, 1), 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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestFunnelStrictStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot
- '''
- 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', 'strict', [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(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
- prop_basic AS prop
- 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), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestFunnelStrictStepsBreakdown.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', 'strict', [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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestStrictFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events
- '''
- 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', 'strict', 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 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(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'))), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))))
- 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: TestStrictFunnelGroupBreakdown.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', 'strict', 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(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'))), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))))
- 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: TestStrictFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events_poe_v2
- '''
- 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,
- max(total_median_conversion_time) 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,
- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(total_conversion_times) OVER ()))])[1] AS total_median_conversion_time,
- rowNumberInAllBlocks() AS row_number,
- if(ifNull(less(row_number, 25), 0), 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', 'strict', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)
- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)
- and isNull(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 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(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'))), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))))
- 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,
- enable_analyzer=1,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestStrictFunnelGroupBreakdown.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', 'strict', 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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestStrictFunnelGroupBreakdown.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', 'strict', 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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.2
- '''
- SELECT source.id,
- source.id AS id
+ 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 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,
+ 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, 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', 'strict', 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,
+ (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,
+ groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,
+ arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'strict', 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,
@@ -827,10 +100,9 @@
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
+ if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,
+ [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
+ if(equals(step_1, 1), 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,
@@ -839,29 +111,22 @@
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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
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',
+ 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=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,
@@ -870,19 +135,26 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.3
+# name: TestFunnelStrictStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot
'''
- SELECT source.id,
- source.id AS id
+ 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 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,
+ 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, 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', 'strict', 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,
+ (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', 'strict', [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,
@@ -896,9 +168,8 @@
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,
+ if(equals(e.event, 'buy'), 1, 0) AS step_1,
+ [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,
prop_basic AS prop
FROM events AS e
LEFT OUTER JOIN
@@ -908,29 +179,22 @@
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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
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',
+ 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=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,
@@ -939,13 +203,27 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.4
+# name: TestStrictFunnelGroupBreakdown.test_funnel_aggregate_by_groups_breakdown_group_person_on_events
'''
- SELECT source.id,
- source.id AS id
+ 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 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_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,
@@ -960,7 +238,7 @@
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.`$group_0` AS aggregation_target,
e.uuid AS uuid,
e.`$session_id` AS `$session_id`,
e.`$window_id` AS `$window_id`,
@@ -970,13 +248,6 @@
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,
@@ -985,21 +256,24 @@
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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
+ WHERE and(equals(e.team_id, 99999), 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'))), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))))
GROUP BY aggregation_target
HAVING 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,
@@ -1008,13 +282,27 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group[new_events_schema.1]
+# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group
'''
- SELECT source.id,
- source.id AS id
+ 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 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_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,
@@ -1038,7 +326,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 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
@@ -1057,18 +345,21 @@
WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
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',
+ 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,
@@ -1077,7 +368,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group[new_events_schema.2]
+# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.1
'''
SELECT source.id,
source.id AS id
@@ -1107,7 +398,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 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
@@ -1126,7 +417,7 @@
WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
GROUP BY aggregation_target
HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))
+ 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
@@ -1146,7 +437,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group[new_events_schema.3]
+# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.2
'''
SELECT source.id,
source.id AS id
@@ -1176,7 +467,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 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
@@ -1195,7 +486,7 @@
WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
GROUP BY aggregation_target
HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))
+ 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
@@ -1215,7 +506,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group[new_events_schema.4]
+# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.3
'''
SELECT source.id,
source.id AS id
@@ -1245,7 +536,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 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
@@ -1264,7 +555,7 @@
WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
GROUP BY aggregation_target
HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))
+ 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
@@ -1284,27 +575,13 @@
use_hive_partitioning=0
'''
# ---
-# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group[new_events_schema]
+# name: TestStrictFunnelGroupBreakdown.test_funnel_breakdown_group.4
'''
- 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
+ SELECT source.id,
+ source.id AS id
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
+ (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,
@@ -1328,7 +605,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 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
@@ -1347,21 +624,18 @@
WHERE and(equals(e.team_id, 99999), and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
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',
+ 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',
readonly=2,
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,
+ 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,
diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr
index 50297450e868..d0abb0c2c428 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr
@@ -260,192 +260,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings[new_events_schema.1]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[2] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'strict', 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- 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
- 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: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings[new_events_schema.2]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[2] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'strict', 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE and(bitTest(steps_bitfield, 1), not(bitTest(steps_bitfield, 2)))
- 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: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings[new_events_schema]
- '''
- SELECT source.id,
- source.id AS id,
- source.matching_events AS matching_events
- FROM
- (SELECT aggregation_target AS actor_id,
- matched_events_array[1] AS matching_events,
- actor_id AS 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'strict', 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.4 AS matched_event_uuids_array_array,
- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,
- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,
- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,
- 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, '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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE bitTest(steps_bitfield, 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_time_to_convert.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr
index cd4ed644b900..b4a2c8f86078 100644
--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr
+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr
@@ -64,71 +64,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelTimeToConvert.test_auto_bin_count_single_step[new_events_schema]
- '''
- SELECT bin_from_seconds,
- person_count,
- arrayAvg(timings) AS averageConversionTime,
- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', timings)])[1] AS medianConversionTime
- FROM
- (SELECT timings AS timings,
- accurateCastOrNull(least(60, greatest(1, ceil(cbrt(ifNull(length(timings), 0))))), 'Int64') AS bin_count,
- floor(arrayMin(timings)) AS min_timing,
- ceil(arrayMax(timings)) AS max_timing,
- ceil(divide(minus(max_timing, min_timing), bin_count)) AS bin_width_seconds_raw,
- if(ifNull(greater(bin_width_seconds_raw, 0), 0), bin_width_seconds_raw, 60) AS bin_width_seconds,
- arrayMap(n -> accurateCastOrNull(round(plus(min_timing, multiply(n, bin_width_seconds))), 'Int64'), range(0, plus(bin_count, 1))) AS buckets,
- arrayMap(timing -> accurateCastOrNull(floor(divide(minus(timing, min_timing), bin_width_seconds)), 'Int64'), timings) AS indices,
- arrayMap(x -> countEqual(indices, minus(x, 1)), range(1, plus(bin_count, 2))) AS counts
- FROM
- (SELECT groupArray(arraySum(arraySlice(timings, 1, 1))) AS timings
- 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, '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, '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('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
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE ifNull(greaterOrEquals(step_reached, 1), 0))) ARRAY
- JOIN counts AS person_count,
- buckets AS bin_from_seconds
- 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=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: TestFunnelTimeToConvert.test_basic_strict
'''
SELECT bin_from_seconds,
@@ -194,71 +129,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelTimeToConvert.test_basic_strict[new_events_schema]
- '''
- SELECT bin_from_seconds,
- person_count,
- arrayAvg(timings) AS averageConversionTime,
- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', timings)])[1] AS medianConversionTime
- FROM
- (SELECT timings AS timings,
- accurateCastOrNull(least(60, greatest(1, ceil(cbrt(ifNull(length(timings), 0))))), 'Int64') AS bin_count,
- floor(arrayMin(timings)) AS min_timing,
- ceil(arrayMax(timings)) AS max_timing,
- ceil(divide(minus(max_timing, min_timing), bin_count)) AS bin_width_seconds_raw,
- if(ifNull(greater(bin_width_seconds_raw, 0), 0), bin_width_seconds_raw, 60) AS bin_width_seconds,
- arrayMap(n -> accurateCastOrNull(round(plus(min_timing, multiply(n, bin_width_seconds))), 'Int64'), range(0, plus(bin_count, 1))) AS buckets,
- arrayMap(timing -> accurateCastOrNull(floor(divide(minus(timing, min_timing), bin_width_seconds)), 'Int64'), timings) AS indices,
- arrayMap(x -> countEqual(indices, minus(x, 1)), range(1, plus(bin_count, 2))) AS counts
- FROM
- (SELECT groupArray(arraySum(arraySlice(timings, 1, 1))) AS timings
- 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, 'first_touch', 'strict', 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, '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(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE ifNull(greaterOrEquals(step_reached, 1), 0))) ARRAY
- JOIN counts AS person_count,
- buckets AS bin_from_seconds
- 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=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: TestFunnelTimeToConvert.test_basic_unordered
'''
SELECT bin_from_seconds,
@@ -324,327 +194,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestFunnelTimeToConvert.test_basic_unordered[new_events_schema]
- '''
- SELECT bin_from_seconds,
- person_count,
- arrayAvg(timings) AS averageConversionTime,
- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', timings)])[1] AS medianConversionTime
- FROM
- (SELECT timings AS timings,
- accurateCastOrNull(least(60, greatest(1, ceil(cbrt(ifNull(length(timings), 0))))), 'Int64') AS bin_count,
- floor(arrayMin(timings)) AS min_timing,
- ceil(arrayMax(timings)) AS max_timing,
- ceil(divide(minus(max_timing, min_timing), bin_count)) AS bin_width_seconds_raw,
- if(ifNull(greater(bin_width_seconds_raw, 0), 0), bin_width_seconds_raw, 60) AS bin_width_seconds,
- arrayMap(n -> accurateCastOrNull(round(plus(min_timing, multiply(n, bin_width_seconds))), 'Int64'), range(0, plus(bin_count, 1))) AS buckets,
- arrayMap(timing -> accurateCastOrNull(floor(divide(minus(timing, min_timing), bin_width_seconds)), 'Int64'), timings) AS indices,
- arrayMap(x -> countEqual(indices, minus(x, 1)), range(1, plus(bin_count, 2))) AS counts
- FROM
- (SELECT groupArray(arraySum(arraySlice(timings, 1, 1))) AS timings
- 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, '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), 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, '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
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE ifNull(greaterOrEquals(step_reached, 1), 0))) ARRAY
- JOIN counts AS person_count,
- buckets AS bin_from_seconds
- 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=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: TestFunnelTimeToConvertUDF.test_auto_bin_count_single_step
- '''
- SELECT bin_from_seconds,
- person_count,
- arrayAvg(timings) AS averageConversionTime
- FROM
- (SELECT groupArray(arraySum(arraySlice(timings, 1, 1))) AS timings,
- accurateCastOrNull(least(60, greatest(1, ceil(cbrt(ifNull(length(timings), 0))))), 'Int64') AS bin_count,
- floor(arrayMin(timings)) AS min_timing,
- ceil(arrayMax(timings)) AS max_timing,
- ceil(divide(minus(max_timing, min_timing), bin_count)) AS bin_width_seconds_raw,
- if(ifNull(greater(bin_width_seconds_raw, 0), 0), bin_width_seconds_raw, 60) AS bin_width_seconds,
- arrayMap(n -> accurateCastOrNull(round(plus(min_timing, multiply(n, bin_width_seconds))), 'Int64'), range(0, plus(bin_count, 1))) AS buckets,
- arrayMap(timing -> accurateCastOrNull(floor(divide(minus(timing, min_timing), bin_width_seconds)), 'Int64'), timings) AS indices,
- arrayMap(x -> countEqual(indices, minus(x, 1)), range(1, plus(bin_count, 2))) AS counts
- 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), multiply(3, step_2)])))) AS events_array,
- [''] AS prop,
- arrayJoin(aggregate_funnel(3, 604800, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)
- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)
- and isNull(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, '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 AS e
- LEFT OUTER JOIN
- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
- person_distinct_id_overrides.distinct_id AS distinct_id
- FROM person_distinct_id_overrides
- WHERE equals(person_distinct_id_overrides.team_id, 99999)
- GROUP BY person_distinct_id_overrides.distinct_id
- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)
- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))
- GROUP BY aggregation_target
- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))
- WHERE ifNull(greaterOrEquals(step_reached, 1), 0)) ARRAY
- JOIN counts AS person_count,
- buckets AS bin_from_seconds
- 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=23622320128,
- enable_analyzer=1,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestFunnelTimeToConvertUDF.test_basic_unordered
- '''
- WITH step_runs AS
- (SELECT aggregation_target AS aggregation_target,
- steps AS steps,
- avg(step_1_conversion_time) AS step_1_average_conversion_time_inner,
- avg(step_2_conversion_time) AS step_2_average_conversion_time_inner,
- median(step_1_conversion_time) AS step_1_median_conversion_time_inner,
- median(step_2_conversion_time) AS step_2_median_conversion_time_inner
- FROM
- (SELECT aggregation_target AS aggregation_target,
- steps AS steps,
- max(steps) OVER (PARTITION BY aggregation_target) AS max_steps,
- step_1_conversion_time AS step_1_conversion_time,
- step_2_conversion_time AS step_2_conversion_time
- FROM
- (SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- latest_1 AS latest_1,
- step_2 AS step_2,
- latest_2 AS latest_2,
- arraySort([latest_0, latest_1, latest_2]) AS event_times,
- arraySum([if(and(ifNull(less(latest_0, latest_1), 0), ifNull(lessOrEquals(latest_1, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), if(and(ifNull(less(latest_0, latest_2), 0), ifNull(lessOrEquals(latest_2, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), 1]) AS steps,
- arraySort([latest_0, latest_1, latest_2]) AS conversion_times,
- if(and(isNotNull(conversion_times[2]), ifNull(lessOrEquals(conversion_times[2], plus(toTimeZone(conversion_times[1], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[1], conversion_times[2]), NULL) AS step_1_conversion_time,
- if(and(isNotNull(conversion_times[3]), ifNull(lessOrEquals(conversion_times[3], plus(toTimeZone(conversion_times[2], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[2], conversion_times[3]), NULL) AS step_2_conversion_time
- FROM
- (SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- min(latest_1) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_1,
- step_2 AS step_2,
- min(latest_2) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_2
- 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,
- if(equals(e.event, 'step one'), 1, 0) AS step_0,
- if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
- if(equals(e.event, 'step two'), 1, 0) AS step_1,
- if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
- if(equals(e.event, 'step three'), 1, 0) AS step_2,
- if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2
- 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 ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 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(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))))
- WHERE ifNull(equals(step_0, 1), 0)
- UNION ALL SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- latest_1 AS latest_1,
- step_2 AS step_2,
- latest_2 AS latest_2,
- arraySort([latest_0, latest_1, latest_2]) AS event_times,
- arraySum([if(and(ifNull(less(latest_0, latest_1), 0), ifNull(lessOrEquals(latest_1, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), if(and(ifNull(less(latest_0, latest_2), 0), ifNull(lessOrEquals(latest_2, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), 1]) AS steps,
- arraySort([latest_0, latest_1, latest_2]) AS conversion_times,
- if(and(isNotNull(conversion_times[2]), ifNull(lessOrEquals(conversion_times[2], plus(toTimeZone(conversion_times[1], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[1], conversion_times[2]), NULL) AS step_1_conversion_time,
- if(and(isNotNull(conversion_times[3]), ifNull(lessOrEquals(conversion_times[3], plus(toTimeZone(conversion_times[2], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[2], conversion_times[3]), NULL) AS step_2_conversion_time
- FROM
- (SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- min(latest_1) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_1,
- step_2 AS step_2,
- min(latest_2) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_2
- 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,
- if(equals(e.event, 'step two'), 1, 0) AS step_0,
- if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
- if(equals(e.event, 'step three'), 1, 0) AS step_1,
- if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
- if(equals(e.event, 'step one'), 1, 0) AS step_2,
- if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2
- 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 ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 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(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))))
- WHERE ifNull(equals(step_0, 1), 0)
- UNION ALL SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- latest_1 AS latest_1,
- step_2 AS step_2,
- latest_2 AS latest_2,
- arraySort([latest_0, latest_1, latest_2]) AS event_times,
- arraySum([if(and(ifNull(less(latest_0, latest_1), 0), ifNull(lessOrEquals(latest_1, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), if(and(ifNull(less(latest_0, latest_2), 0), ifNull(lessOrEquals(latest_2, plus(toTimeZone(latest_0, 'UTC'), toIntervalDay(14))), 0)), 1, 0), 1]) AS steps,
- arraySort([latest_0, latest_1, latest_2]) AS conversion_times,
- if(and(isNotNull(conversion_times[2]), ifNull(lessOrEquals(conversion_times[2], plus(toTimeZone(conversion_times[1], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[1], conversion_times[2]), NULL) AS step_1_conversion_time,
- if(and(isNotNull(conversion_times[3]), ifNull(lessOrEquals(conversion_times[3], plus(toTimeZone(conversion_times[2], 'UTC'), toIntervalDay(14))), 0)), dateDiff('second', conversion_times[2], conversion_times[3]), NULL) AS step_2_conversion_time
- FROM
- (SELECT aggregation_target AS aggregation_target,
- timestamp AS timestamp,
- step_0 AS step_0,
- latest_0 AS latest_0,
- step_1 AS step_1,
- min(latest_1) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_1,
- step_2 AS step_2,
- min(latest_2) OVER (PARTITION BY aggregation_target
- ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) AS latest_2
- 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,
- if(equals(e.event, 'step three'), 1, 0) AS step_0,
- if(ifNull(equals(step_0, 1), 0), timestamp, NULL) AS latest_0,
- if(equals(e.event, 'step one'), 1, 0) AS step_1,
- if(ifNull(equals(step_1, 1), 0), timestamp, NULL) AS latest_1,
- if(equals(e.event, 'step two'), 1, 0) AS step_2,
- if(ifNull(equals(step_2, 1), 0), timestamp, NULL) AS latest_2
- 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 ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 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(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))))
- WHERE ifNull(equals(step_0, 1), 0)))
- GROUP BY aggregation_target,
- steps
- HAVING ifNull(equals(steps, max(max_steps)), isNull(steps)
- and isNull(max(max_steps)))),
- histogram_params AS
- (SELECT ifNull(floor(min(step_runs.step_1_average_conversion_time_inner)), 0) AS from_seconds,
- ifNull(ceil(max(step_runs.step_1_average_conversion_time_inner)), 1) AS to_seconds,
- round(avg(step_runs.step_1_average_conversion_time_inner), 2) AS average_conversion_time,
- count() AS sample_count,
- least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count,
- ceil(divide(minus(to_seconds, from_seconds), bin_count)) AS bin_width_seconds_raw,
- if(ifNull(greater(bin_width_seconds_raw, 0), 0), bin_width_seconds_raw, 60) AS bin_width_seconds
- FROM step_runs
- WHERE isNotNull(step_runs.step_1_average_conversion_time_inner)),
- (SELECT histogram_params.bin_width_seconds AS bin_width_seconds
- FROM histogram_params) AS bin_width_seconds,
- (SELECT histogram_params.bin_count AS bin_count
- FROM histogram_params) AS bin_count,
- (SELECT histogram_params.from_seconds AS from_seconds
- FROM histogram_params) AS histogram_from_seconds,
- (SELECT histogram_params.to_seconds AS to_seconds
- FROM histogram_params) AS histogram_to_seconds,
- (SELECT histogram_params.average_conversion_time AS average_conversion_time
- FROM histogram_params) AS histogram_average_conversion_time
- SELECT fill.bin_from_seconds AS bin_from_seconds,
- results.person_count AS person_count,
- histogram_average_conversion_time AS average_conversion_time
- FROM
- (SELECT plus(histogram_from_seconds, multiply(floor(divide(minus(step_runs.step_1_average_conversion_time_inner, histogram_from_seconds), bin_width_seconds)), bin_width_seconds)) AS bin_from_seconds,
- count() AS person_count
- FROM step_runs
- GROUP BY bin_from_seconds) AS results
- RIGHT OUTER JOIN
- (SELECT plus(histogram_from_seconds, multiply(numbers.number, bin_width_seconds)) AS bin_from_seconds
- FROM numbers(plus(ifNull(bin_count, 0), 1)) AS numbers) AS fill ON equals(results.bin_from_seconds, fill.bin_from_seconds)
- ORDER BY fill.bin_from_seconds 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=23622320128,
- enable_analyzer=1,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
diff --git a/posthog/hogql_queries/insights/retention/retention_query_runner.py b/posthog/hogql_queries/insights/retention/retention_query_runner.py
index f25454133fcd..901191ac527a 100644
--- a/posthog/hogql_queries/insights/retention/retention_query_runner.py
+++ b/posthog/hogql_queries/insights/retention/retention_query_runner.py
@@ -44,6 +44,7 @@ from posthog.hogql_queries.insights.retention.retention_validation_rules import
DisallowGroupAggregationWithDataWarehouse24HourWindows,
DisallowPropertyAggregationWith24HourWindows,
DisallowUnsupportedDataWarehouseTimestampField,
+ RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget,
)
from posthog.hogql_queries.insights.utils.breakdowns import (
ALL_USERS_COHORT_ID,
@@ -151,6 +152,7 @@ class RetentionQueryRunner(AnalyticsQueryRunner[RetentionQueryResponse]):
DisallowPropertyAggregationWith24HourWindows(),
DisallowUnsupportedDataWarehouseSettings(),
DisallowUnsupportedDataWarehouseTimestampField(),
+ RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget(),
)
@cached_property
diff --git a/posthog/hogql_queries/insights/retention/retention_validation_rules.py b/posthog/hogql_queries/insights/retention/retention_validation_rules.py
index 42c4acc14633..fe420a6fd45d 100644
--- a/posthog/hogql_queries/insights/retention/retention_validation_rules.py
+++ b/posthog/hogql_queries/insights/retention/retention_validation_rules.py
@@ -102,6 +102,28 @@ class DisallowUnsupportedDataWarehouseTimestampField:
)
+class RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget:
+ """The "Custom entities" aggregation target is only available when both retention entities read from the
+ data warehouse. Other entities are person/group based."""
+
+ code = "retention_custom_aggregation_target_requires_data_warehouse_entities"
+
+ def validate(self, context: QueryValidationContext[RetentionQuery]) -> None:
+ retention_filter = context.query.retentionFilter
+ if not retention_filter.customAggregationTarget:
+ return
+ both_entities_data_warehouse = all(
+ entity is not None and entity.type == EntityType.DATA_WAREHOUSE
+ for entity in (retention_filter.targetEntity, retention_filter.returningEntity)
+ )
+ if both_entities_data_warehouse:
+ return
+ raise ValidationError(
+ "Custom entity aggregation target requires both retention entities to be data warehouse entities.",
+ code=self.code,
+ )
+
+
class DisallowPropertyAggregationWith24HourWindows:
"""The 24-hour-window builder never emits the retention_value column that sum/avg aggregation reads in the
outer query."""
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.ambr
index 537491c414f4..66ce397a6d2c 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.3
- '''
- 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
- 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.4
- '''
- 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
- 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.5
- '''
- 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
- 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
'''
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.3
- '''
- 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
- 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.4
- '''
- 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
- 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.5
- '''
- 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
- 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_retention_24h_window_calculation
'''
SELECT actor_activity.start_interval_index AS start_event_matching_interval,
@@ -641,7 +413,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation.4
+# 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,
@@ -652,7 +424,7 @@
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
+ 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,
@@ -682,18 +454,27 @@
use_hive_partitioning=0
'''
# ---
-# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation.5
+# name: TestRetention.test_month_interval_with_person_on_events_v2
+ '''
+
+ SELECT DISTINCT person_id
+ FROM events
+ WHERE team_id = 99999
+ AND distinct_id = 'person2'
+ '''
+# ---
+# name: TestRetention.test_month_interval_with_person_on_events_v2.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,
+ 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), 3), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base
+ 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,
@@ -702,7 +483,7 @@
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')))
+ 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,
@@ -723,26 +504,34 @@
use_hive_partitioning=0
'''
# ---
-# name: TestClickhouseRetentionGroupAggregation.test_retention_24h_window_calculation.6
+# 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
+ count(DISTINCT actor_activity.actor_id) AS count,
+ sum(actor_activity.retention_value) AS aggregation_value
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
- 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 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,
+ arrayFlatten(groupArray(retention_events._start_event_data)) AS _start_event_data,
+ arrayFlatten(groupArray(retention_events._return_event_data)) AS _return_event_data,
+ 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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
+ and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
+ and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
+ and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).1 AS intervals_from_base,
+ arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
+ and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
+ and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
+ and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).2 AS retention_value
+ FROM
(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
+ arraySort(arrayDistinct(arrayMap(x -> x.1, groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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_timestamps,
+ [] AS return_event_timestamps,
+ groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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,
+ [] AS _return_event_data
FROM events
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
@@ -751,50 +540,13 @@
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')))
+ 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('signed_up')), equals(events.event, 'signed_up'))
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.7
- '''
- 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
- 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
+ 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
+ [] 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
FROM events
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
@@ -803,183 +555,8 @@
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: 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_month_interval_with_person_on_events_v2
- '''
-
- SELECT DISTINCT person_id
- FROM events
- WHERE team_id = 99999
- AND distinct_id = 'person2'
- '''
-# ---
-# name: TestRetention.test_month_interval_with_person_on_events_v2.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(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
- 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_month_interval_with_person_on_events_v2.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 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
- 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')))
+ 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')), equals(events.event, 'purchased'))
+ GROUP BY actor_id) AS retention_events
GROUP BY actor_id
HAVING 1) AS actor_activity
GROUP BY start_event_matching_interval,
@@ -1000,222 +577,7 @@
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 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,
- arrayFlatten(groupArray(retention_events._start_event_data)) AS _start_event_data,
- arrayFlatten(groupArray(retention_events._return_event_data)) AS _return_event_data,
- 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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
- and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
- and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).1 AS intervals_from_base,
- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
- and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
- and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).2 AS retention_value
- FROM
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,
- arraySort(arrayDistinct(arrayMap(x -> x.1, groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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_timestamps,
- [] AS return_event_timestamps,
- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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,
- [] AS _return_event_data
- 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('signed_up')), equals(events.event, 'signed_up'))
- 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] 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
- 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')), equals(events.event, 'purchased'))
- 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 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.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,
- sum(actor_activity.retention_value) AS aggregation_value
- 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,
- arrayFlatten(groupArray(retention_events._start_event_data)) AS _start_event_data,
- arrayFlatten(groupArray(retention_events._return_event_data)) AS _return_event_data,
- 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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
- and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
- and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).1 AS intervals_from_base,
- arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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(ifNull(greater(x.1, date_range[plus(start_interval_index, 1)]), 0), and(ifNull(equals(x.1, date_range[plus(start_interval_index, 1)]), isNull(x.1)
- and isNull(date_range[plus(start_interval_index, 1)])), ifNull(greater(x.3, arrayMin(arrayMap(y -> y.3, arrayFilter(z -> ifNull(equals(z.1, date_range[plus(start_interval_index, 1)]), isNull(z.1)
- and isNull(date_range[plus(start_interval_index, 1)])), _start_event_data)))), 0))), _return_event_data))))).2 AS retention_value
- FROM
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,
- arraySort(arrayDistinct(arrayMap(x -> x.1, groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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_timestamps,
- [] AS return_event_timestamps,
- groupArrayIf(tuple(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), 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,
- [] AS _return_event_data
- 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('signed_up')), equals(events.event, 'signed_up'))
- 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] 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
- 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')), equals(events.event, 'purchased'))
- 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 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 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('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 7)) AS date_range,
- arrayFlatten(groupArray(retention_events._start_event_data)) AS _start_event_data,
- arrayFlatten(groupArray(retention_events._return_event_data)) AS _return_event_data,
- 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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,
- arraySort(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] AS return_event_timestamps,
- 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,
- [] AS _return_event_data
- 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')), equals(events.event, '$pageview'))
- 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] 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
- 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')), equals(events.event, '$pageview'))
- 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 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.1
+# 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,
@@ -1232,533 +594,13 @@
arrayJoin(arrayConcat(arrayFilter(x -> ifNull(greaterOrEquals(x.1, 0), 0), arrayMap(item -> tuple(accurateCastOrNull(if(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
and isNull(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(ifNull(equals(item.1, date_range[plus(start_interval_index, 1)]), isNull(item.1)
- and isNull(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
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,
- arraySort(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] AS return_event_timestamps,
- 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,
- [] AS _return_event_data
- 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')), equals(events.event, '$pageview'))
- 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
- [] 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
- 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')), equals(events.event, '$pageview'))
- 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 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.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, '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_first_ever_single_scan_filters_by_event_name_only
- '''
- 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(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toIntervalDay(1)), 'UTC')], []) AS start_event_timestamps,
- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,
- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)), 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('act_a')))
- 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_ever_single_scan_filters_by_event_name_only.1
- '''
- SELECT actor_activity.start_interval_index AS start_event_matching_interval,
- actor_activity.intervals_from_base AS intervals_from_base,
- actor_activity.breakdown_value AS breakdown_value,
- 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(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toIntervalDay(1)), 'UTC')], []) AS start_event_timestamps,
- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,
- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'act_a'), 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,
- argMinIf(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', '')), ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')) AS breakdown_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), in(events.event, tuple('act_a', 'signup')), or(in(events.event, tuple('signup')), and(in(events.event, tuple('act_a')), 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'))))))
- GROUP BY actor_id
- HAVING 1) AS actor_activity
- GROUP BY start_event_matching_interval,
- intervals_from_base,
- breakdown_value
- ORDER BY breakdown_value ASC,
- 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_ever_single_scan_filters_by_event_name_only.2
- '''
- SELECT actor_activity.start_interval_index AS start_event_matching_interval,
- actor_activity.intervals_from_base AS intervals_from_base,
- actor_activity.breakdown_value AS breakdown_value,
- 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(has(arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'signup'), 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, toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), 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, 5)) AS date_range,
- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'act_a'), 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,
- argMinIf(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', '')), ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')) AS breakdown_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), in(events.event, tuple('act_a', 'signup')))
- GROUP BY actor_id
- HAVING 1) AS actor_activity
- GROUP BY start_event_matching_interval,
- intervals_from_base,
- breakdown_value
- ORDER BY breakdown_value ASC,
- 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_ever_single_scan_filters_by_event_name_only.3
- '''
- SELECT actor_activity.start_interval_index AS start_event_matching_interval,
- actor_activity.intervals_from_base AS intervals_from_base,
- actor_activity.breakdown_value AS breakdown_value,
- 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(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toIntervalDay(1)), 'UTC')], []) AS start_event_timestamps,
- arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,
- arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'act_a'), 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,
- argMinIf(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', '')), ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')) AS breakdown_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), in(events.event, tuple('act_a', 'signup')), or(in(events.event, tuple('signup')), and(in(events.event, tuple('act_a')), 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'))))))
- GROUP BY actor_id
- HAVING 1) AS actor_activity
- GROUP BY start_event_matching_interval,
- intervals_from_base,
- breakdown_value
- ORDER BY breakdown_value ASC,
- 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(and(greaterOrEquals(minIf(events.timestamp, equals(events.matches_start, 1)), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(minIf(events.timestamp, equals(events.matches_start, 1)), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(minIf(events.timestamp, equals(events.matches_start, 1)), toIntervalDay(1)), 'UTC')], []) 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 events.person_id AS actor_id,
- if(and(ifNull(greaterOrEquals(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), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), 0), ifNull(less(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), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), 0)), [toTimeZone(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)), 'UTC')], []) 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
- 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
- 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.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 events.person_id AS actor_id,
- if(and(ifNull(greaterOrEquals(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), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), 0), ifNull(less(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), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), 0)), [toTimeZone(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)), 'UTC')], []) 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
+ and isNull(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
- (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
+ (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id,
+ arraySort(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
+ [] AS return_event_timestamps,
+ 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,
+ [] AS _return_event_data
FROM events
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
@@ -1767,12 +609,13 @@
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
+ 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')), equals(events.event, '$pageview'))
+ 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(arrayDistinct(arrayMap(x -> x.1, 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_timestamps,
+ [] 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
FROM events
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
@@ -1781,7 +624,8 @@
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
+ 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')), equals(events.event, '$pageview'))
+ GROUP BY actor_id) AS retention_events
GROUP BY actor_id
HAVING 1) AS actor_activity
GROUP BY start_event_matching_interval,
@@ -1802,16 +646,16 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_retention_with_user_properties_via_action
+# 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(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,
+ 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, '$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,
+ 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
@@ -1822,17 +666,7 @@
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 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), 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,
@@ -1853,18 +687,20 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_retention_with_user_properties_via_action.1
+# name: TestRetention.test_retention_first_ever_single_scan_filters_by_event_name_only
'''
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(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'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)))), minIf(toTimeZone(events.timestamp, 'UTC'), and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0))), NULL), toIntervalDay(1)), 'UTC')], []) AS start_event_timestamps,
+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,
+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(and(equals(events.event, 'act_a'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$current_url'), ''), 'null'), '^"|"$', ''), '%/dash%'), 0)), 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,
@@ -1873,17 +709,7 @@
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 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('act_a')))
GROUP BY actor_id
HAVING 1) AS actor_activity
GROUP BY start_event_matching_interval,
@@ -1904,18 +730,22 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_timezones
+# name: TestRetention.test_retention_first_ever_single_scan_filters_by_event_name_only.1
'''
SELECT actor_activity.start_interval_index AS start_event_matching_interval,
actor_activity.intervals_from_base AS intervals_from_base,
+ actor_activity.breakdown_value AS breakdown_value,
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
+ if(and(greaterOrEquals(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(if(equals(minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup'))), minIf(toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')), NULL), toIntervalDay(1)), 'UTC')], []) AS start_event_timestamps,
+ arrayMap(x -> plus(toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1)), toIntervalDay(x)), range(0, 5)) AS date_range,
+ arraySort(groupUniqArrayIf(toStartOfDay(toTimeZone(events.timestamp, 'UTC')), and(equals(events.event, 'act_a'), 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,
+ argMinIf(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'plan'), ''), 'null'), '^"|"$', '')), ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, 'signup')) AS breakdown_value
FROM events
LEFT OUTER JOIN
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
@@ -1924,12 +754,14 @@
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')))
+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('act_a', 'signup')), or(in(events.event, tuple('signup')), and(in(events.event, tuple('act_a')), 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'))))))
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,
+ breakdown_value
+ ORDER BY breakdown_value ASC,
+ start_event_matching_interval ASC,
intervals_from_base ASC
LIMIT 100000 SETTINGS readonly=2,
max_execution_time=600,
@@ -1945,27 +777,49 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_timezones.1
+# 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 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
- 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')))
+ (SELECT events.person_id AS actor_id,
+ if(and(greaterOrEquals(minIf(events.timestamp, equals(events.matches_start, 1)), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), less(minIf(events.timestamp, equals(events.matches_start, 1)), toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), [toTimeZone(toStartOfInterval(minIf(events.timestamp, equals(events.matches_start, 1)), toIntervalDay(1)), 'UTC')], []) 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,
@@ -1986,27 +840,49 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_timezones.2
+# 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,
- 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
- 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')))
+ (SELECT events.person_id AS actor_id,
+ if(and(ifNull(greaterOrEquals(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), toStartOfInterval(assumeNotNull(toDateTime('2020-06-10 00:00:00', 'UTC')), toIntervalDay(1))), 0), ifNull(less(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), toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), 0)), [toTimeZone(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)), 'UTC')], []) 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
GROUP BY actor_id
HAVING 1) AS actor_activity
GROUP BY start_event_matching_interval,
@@ -2027,18 +903,18 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_timezones.3
+# 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,
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,
+ 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), 11), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base
+ 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,
@@ -2047,7 +923,17 @@
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')))
+ 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')))
GROUP BY actor_id
HAVING 1) AS actor_activity
GROUP BY start_event_matching_interval,
@@ -2068,18 +954,18 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_week_interval
+# name: TestRetention.test_timezones
'''
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,
+ 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), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base
+ 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,
@@ -2088,7 +974,7 @@
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')))
+ 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,
@@ -2109,18 +995,18 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_week_interval.1
+# name: TestRetention.test_timezones.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,
+ 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), 7), _timestamp), 1), return_event_timestamps)))) AS intervals_from_base
+ 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,
@@ -2129,7 +1015,7 @@
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')))
+ 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,
@@ -2150,16 +1036,16 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_week_interval.2
+# name: TestRetention.test_week_interval
'''
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,
+ 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
@@ -2170,7 +1056,7 @@
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')))
+ 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,
@@ -2191,7 +1077,7 @@
use_hive_partitioning=0
'''
# ---
-# name: TestRetention.test_week_interval.3
+# name: TestRetention.test_week_interval.1
'''
SELECT actor_activity.start_interval_index AS start_event_matching_interval,
actor_activity.intervals_from_base AS intervals_from_base,
diff --git a/posthog/hogql_queries/insights/retention/test/test_retention_validation_rules.py b/posthog/hogql_queries/insights/retention/test/test_retention_validation_rules.py
index bf6646b2d4fb..a3a0a64c7b97 100644
--- a/posthog/hogql_queries/insights/retention/test/test_retention_validation_rules.py
+++ b/posthog/hogql_queries/insights/retention/test/test_retention_validation_rules.py
@@ -11,6 +11,7 @@ from posthog.hogql_queries.insights.retention.retention_validation_rules import
DisallowCumulativeWith24HourWindows,
DisallowGroupAggregationWithDataWarehouse24HourWindows,
DisallowPropertyAggregationWith24HourWindows,
+ RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget,
)
from posthog.hogql_queries.validation.rules import DisallowUnsupportedDataWarehouseSettings
from posthog.hogql_queries.validation.validation import QueryValidationContext
@@ -211,3 +212,51 @@ class TestRetentionValidationRules(BaseTest):
self.assertIn("Sum and average aggregation are not supported for 24 hour windows.", str(context.exception))
self.assertEqual(context.exception.get_codes(), ["retention_24_hour_windows_property_aggregation_unsupported"])
+
+ @parameterized.expand(
+ [
+ ("no_custom_target_events_entities", False, "events", "events", False),
+ ("custom_target_events_entities", True, "events", "events", True),
+ ("custom_target_unset_entities", True, None, None, True),
+ ("custom_target_only_target_dwh", True, "dwh", "events", True),
+ ("custom_target_only_returning_dwh", True, "events", "dwh", True),
+ ("custom_target_both_dwh", True, "dwh", "dwh", False),
+ ]
+ )
+ def test_require_data_warehouse_entities_for_custom_aggregation_target(
+ self,
+ _name: str,
+ custom_aggregation_target: bool,
+ target_entity: str | None,
+ returning_entity: str | None,
+ raises_error: bool,
+ ) -> None:
+ def entity(kind: str | None) -> dict[str, str] | None:
+ if kind == "dwh":
+ return self._data_warehouse_entity()
+ if kind == "events":
+ return {"id": "$pageview", "type": EntityType.EVENTS}
+ return None
+
+ query = RetentionQuery(
+ retentionFilter=RetentionFilter(
+ customAggregationTarget=custom_aggregation_target,
+ targetEntity=entity(target_entity),
+ returningEntity=entity(returning_entity),
+ )
+ )
+
+ if not raises_error:
+ RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget().validate(self._context(query))
+ return
+
+ with self.assertRaises(ValidationError) as context:
+ RequireRetentionDataWarehouseEntitiesForCustomAggregationTarget().validate(self._context(query))
+
+ self.assertIn(
+ "Custom entity aggregation target requires both retention entities to be data warehouse entities.",
+ str(context.exception),
+ )
+ self.assertEqual(
+ context.exception.get_codes(), ["retention_custom_aggregation_target_requires_data_warehouse_entities"]
+ )
diff --git a/posthog/hogql_queries/test/__snapshots__/test_events_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_events_query_runner.ambr
index e9f38a8f853e..caff3c804432 100644
--- a/posthog/hogql_queries/test/__snapshots__/test_events_query_runner.ambr
+++ b/posthog/hogql_queries/test/__snapshots__/test_events_query_runner.ambr
@@ -25,34 +25,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_absolute_date_range[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2020-01-12 23:59:59.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-12 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101)), and(equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2020-01-12 23:59:59.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-12 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_cursor_not_returned_for_aggregation_query
'''
SELECT count() AS `count()`,
@@ -76,29 +48,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_cursor_not_returned_for_aggregation_query[new_events_schema]
- '''
- SELECT count() AS `count()`,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- GROUP BY toTimeZone(events.timestamp, 'UTC')
- ORDER BY count() DESC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_cursor_not_returned_for_non_timestamp_order
'''
SELECT events.event AS event,
@@ -126,33 +75,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_cursor_not_returned_for_non_timestamp_order[new_events_schema]
- '''
- SELECT events.event AS event,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY events.event ASC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY events.event ASC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_asc
'''
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'idx'), ''), 'null'), '^"|"$', '') AS idx,
@@ -234,87 +156,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_asc[new_events_schema.1]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-11 12:00:02.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-11 12:00:02.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_asc[new_events_schema.2]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-11 12:00:04.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-11 12:00:04.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_asc[new_events_schema]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_desc
'''
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'idx'), ''), 'null'), '^"|"$', '') AS idx,
@@ -396,87 +237,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_desc[new_events_schema.1]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-11 12:00:04.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-11 12:00:04.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_desc[new_events_schema.2]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-11 12:00:02.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-11 12:00:02.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
-# name: TestEventsQueryRunner.test_cursor_pagination_multi_page_desc[new_events_schema]
- '''
- SELECT if(notEquals(toJSONString(events.properties.^idx), '{}'), toJSONString(events.properties.^idx), if(isNull(events.properties.idx), NULL, if(startsWith(dynamicType(events.properties.idx), 'DateTime'), replaceOne(toString(events.properties.idx), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.idx), 'Array'), startsWith(dynamicType(events.properties.idx), 'Map'), startsWith(dynamicType(events.properties.idx), 'Tuple')), toJSONString(events.properties.idx), toString(events.properties.idx))))) AS idx,
- toTimeZone(events.timestamp, 'UTC') AS timestamp
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_cursor_with_star_select
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -503,34 +263,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_cursor_with_star_select[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3)), and(less(events.timestamp, toDateTime64('2020-01-12 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC
- LIMIT 3
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_element_chain_property_filter
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -557,34 +289,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_element_chain_property_filter[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), notILike(toString(events.elements_chain), '%div%'), equals(events.event, '$autocapture'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-20 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101)), and(notILike(toString(events.elements_chain), '%div%'), equals(events.event, '$autocapture'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-20 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_presorted_events_table
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -611,34 +315,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_presorted_events_table[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^some_prop), '{}'), toJSONString(events.properties.^some_prop), if(isNull(events.properties.some_prop), NULL, if(startsWith(dynamicType(events.properties.some_prop), 'DateTime'), replaceOne(toString(events.properties.some_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.some_prop), 'Array'), startsWith(dynamicType(events.properties.some_prop), 'Map'), startsWith(dynamicType(events.properties.some_prop), 'Tuple')), toJSONString(events.properties.some_prop), toString(events.properties.some_prop))))), 'a'), 0), equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101)), and(ifNull(equals(if(notEquals(toJSONString(events.properties.^some_prop), '{}'), toJSONString(events.properties.^some_prop), if(isNull(events.properties.some_prop), NULL, if(startsWith(dynamicType(events.properties.some_prop), 'DateTime'), replaceOne(toString(events.properties.some_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.some_prop), 'Array'), startsWith(dynamicType(events.properties.some_prop), 'Map'), startsWith(dynamicType(events.properties.some_prop), 'Tuple')), toJSONString(events.properties.some_prop), toString(events.properties.some_prop))))), 'a'), 0), equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_presorted_events_table_multiple_order_by
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -666,34 +342,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_presorted_events_table_multiple_order_by[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC')))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC, events.event ASC
- LIMIT 101)), and(equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC'))))
- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC, events.event ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_presorted_events_table_order_by_event
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -720,34 +368,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_presorted_events_table_order_by_event[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC')))
- ORDER BY events.event ASC
- LIMIT 101)), and(less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC'))))
- ORDER BY events.event ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestEventsQueryRunner.test_presorted_events_table_order_by_property
'''
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
@@ -774,31 +394,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestEventsQueryRunner.test_presorted_events_table_order_by_property[new_events_schema]
- '''
- SELECT tuple(events.uuid, events.event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC'), events.person_mode) AS `tuple(uuid, event, properties, toTimeZone(timestamp, 'UTC'), team_id, distinct_id, elements_chain, toTimeZone(created_at, 'UTC'), person_mode)`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), in(events.uuid,
- (SELECT events.uuid AS uuid
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC')))
- ORDER BY if(notEquals(toJSONString(events.properties.^priority), '{}'), toJSONString(events.properties.^priority), if(isNull(events.properties.priority), NULL, if(startsWith(dynamicType(events.properties.priority), 'DateTime'), replaceOne(toString(events.properties.priority), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.priority), 'Array'), startsWith(dynamicType(events.properties.priority), 'Map'), startsWith(dynamicType(events.properties.priority), 'Tuple')), toJSONString(events.properties.priority), toString(events.properties.priority))))) ASC
- LIMIT 101)), and(equals(events.event, '$pageview'), less(events.timestamp, toDateTime64('2021-01-21 00:00:05.000000', 6, 'UTC')), greater(events.timestamp, toDateTime64('2021-01-14 00:00:00.000000', 6, 'UTC'))))
- ORDER BY if(notEquals(toJSONString(events.properties.^priority), '{}'), toJSONString(events.properties.^priority), if(isNull(events.properties.priority), NULL, if(startsWith(dynamicType(events.properties.priority), 'DateTime'), replaceOne(toString(events.properties.priority), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.priority), 'Array'), startsWith(dynamicType(events.properties.priority), 'Map'), startsWith(dynamicType(events.properties.priority), 'Tuple')), toJSONString(events.properties.priority), toString(events.properties.priority))))) ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- 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/test/__snapshots__/test_sessions_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_sessions_query_runner.ambr
index 455141570938..394be1f1a878 100644
--- a/posthog/hogql_queries/test/__snapshots__/test_sessions_query_runner.ambr
+++ b/posthog/hogql_queries/test/__snapshots__/test_sessions_query_runner.ambr
@@ -300,36 +300,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsQueryRunner.test_filter_by_event_properties_without_event_name[new_events_schema]
- '''
- SELECT sessions.session_id AS session_id
- FROM
- (SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,
- min(toTimeZone(raw_sessions.min_timestamp, 'UTC')) AS `$start_timestamp`,
- raw_sessions.session_id_v7 AS session_id_v7
- FROM raw_sessions
- WHERE and(equals(raw_sessions.team_id, 99999), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64('2024-01-01 14:00:05.000000', 6, 'UTC'), toIntervalDay(3))), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime64('2024-01-01 00:00:00.000000', 6, 'UTC'), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS sessions
- WHERE and(globalIn(sessions.session_id,
- (SELECT DISTINCT events.`$session_id` AS `$session_id`
- FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), and(equals(events.properties.`$current_url`, 'https://example.com/pricing'), isNotNull(events.properties.`$current_url`)), greater(events.timestamp, toDateTime64('2024-01-01 00:00:00.000000', 6, 'UTC')), less(events.timestamp, toDateTime64('2024-01-01 14:00:05.000000', 6, 'UTC'))))), less(sessions.`$start_timestamp`, toDateTime64('2024-01-01 14:00:05.000000', 6, 'UTC')), greater(sessions.`$start_timestamp`, toDateTime64('2024-01-01 00:00:00.000000', 6, 'UTC')))
- ORDER BY sessions.session_id ASC
- LIMIT 101
- OFFSET 0 SETTINGS readonly=2,
- max_execution_time=60,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=0,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- optimize_rewrite_aggregate_function_with_if=0,
- optimize_min_inequality_conjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestSessionsQueryRunner.test_filter_by_person_property
'''
SELECT sessions.session_id AS session_id,
diff --git a/posthog/hogql_queries/test/__snapshots__/test_sessions_timeline_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_sessions_timeline_query_runner.ambr
index 55ffc382ec54..b0646b221d21 100644
--- a/posthog/hogql_queries/test/__snapshots__/test_sessions_timeline_query_runner.ambr
+++ b/posthog/hogql_queries/test/__snapshots__/test_sessions_timeline_query_runner.ambr
@@ -71,80 +71,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_before_and_after[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_before_and_after_defaults
'''
SELECT e.uuid AS uuid,
@@ -217,80 +143,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_before_and_after_defaults[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_event_limit_and_has_more
'''
SELECT e.uuid AS uuid,
@@ -363,80 +215,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_event_limit_and_has_more[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 3)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_formal_and_informal_sessions_global
'''
SELECT e.uuid AS uuid,
@@ -509,80 +287,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_formal_and_informal_sessions_global[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_formal_session_with_recording
'''
SELECT e.uuid AS uuid,
@@ -655,80 +359,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_formal_session_with_recording[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_formal_sessions_for_person
'''
SELECT e.uuid AS uuid,
@@ -801,80 +431,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_formal_sessions_for_person[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), equals(if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id), 'd63e1ecf-f92f-1e50-71f9-501e16e9aebe'))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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: TestSessionsTimelineQueryRunner.test_formal_sessions_global
'''
SELECT e.uuid AS uuid,
@@ -947,77 +503,3 @@
use_hive_partitioning=0
'''
# ---
-# name: TestSessionsTimelineQueryRunner.test_formal_sessions_global[new_events_schema]
- '''
- SELECT e.uuid AS uuid,
- e.timestamp AS timestamp,
- e.event AS event,
- e.properties AS properties,
- e.distinct_id AS distinct_id,
- e.elements_chain AS elements_chain,
- e.session_id AS formal_session_id,
- first_value(e.uuid) OVER (PARTITION BY tuple(e.person_id, e.session_id_flip_index)
- ORDER BY toInt64(e.timestamp) ASC RANGE BETWEEN 1800 PRECEDING AND CURRENT ROW) AS informal_session_uuid,
- dateDiff('s', sre.start_time, sre.end_time) AS recording_duration_s
- FROM
- (SELECT uuid AS uuid,
- person_id AS person_id,
- timestamp AS timestamp,
- event AS event,
- properties AS properties,
- distinct_id AS distinct_id,
- elements_chain AS elements_chain,
- session_id AS session_id,
- sum(if(ifNull(equals(session_id, prev_session_id), isNull(session_id)
- and isNull(prev_session_id)), 0, 1)) OVER (PARTITION BY person_id
- ORDER BY timestamp ASC ROWS UNBOUNDED PRECEDING) AS session_id_flip_index
- FROM
- (SELECT event_source.uuid AS uuid,
- if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id) AS person_id,
- toTimeZone(event_source.timestamp, 'UTC') AS timestamp,
- event_source.event AS event,
- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'
- AND NOT (kv.2 = '[]'
- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(event_source.properties)))), ','), '}') AS properties,
- event_source.distinct_id AS distinct_id,
- event_source.elements_chain AS elements_chain,
- event_source.`$session_id` AS session_id,
- lagInFrame(event_source.`$session_id`, 1) OVER (PARTITION BY if(not(empty(event_source__override.distinct_id)), event_source__override.person_id, event_source.person_id)
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') ASC) AS prev_session_id
- FROM events_json AS event_source
- 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 event_source__override ON equals(event_source.distinct_id, event_source__override.distinct_id)
- WHERE and(equals(event_source.team_id, 99999), greater(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), less(event_source.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')))
- ORDER BY toTimeZone(event_source.timestamp, 'UTC') DESC
- LIMIT 1001)) AS e
- LEFT JOIN
- (SELECT session_replay_events.start_time AS start_time,
- session_replay_events.end_time AS end_time,
- session_replay_events.session_id AS session_id
- FROM
- (SELECT min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
- max(toTimeZone(session_replay_events.max_last_timestamp, 'UTC')) AS end_time,
- session_replay_events.session_id AS session_id
- FROM session_replay_events
- WHERE equals(session_replay_events.team_id, 99999)
- GROUP BY session_replay_events.session_id) AS session_replay_events) AS sre ON equals(e.session_id, sre.session_id)
- ORDER BY e.timestamp DESC
- 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/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
index 10ddec6c16a3..da8b2f78c636 100644
--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr
+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
@@ -1631,1126 +1631,3 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.10]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.11]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.12]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.13]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.14]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.15]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.16]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.17]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.18]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.19]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.1]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.20]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.21]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.22]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.23]
- '''
-
- SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND ifNull(properties.`$lib`, '') IN ('posthog-node')
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_lib`) != '{}', toJSONString(properties.^`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_lib`), 'Tuple'), toJSONString(properties.`$ai_lib`), if(startsWith(dynamicType(properties.`$ai_lib`), 'DateTime'), replaceOne(toString(properties.`$ai_lib`), ' ', 'T'), toString(properties.`$ai_lib`)))), ''), '^"|"$', '') IN ('posthog-openclaw',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- ai_lib
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.24]
- '''
-
- SELECT team_id,
- multiIf(ifNull(properties.`$lib`, '') = 'web', 'web', ifNull(properties.`$lib`, '') = 'js', 'web_lite', ifNull(properties.`$lib`, '') = 'posthog-node', 'node', ifNull(properties.`$lib`, '') = 'posthog-edge', 'node', ifNull(properties.`$lib`, '') = 'posthog-android', 'android', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios', ifNull(properties.`$lib`, '') = 'posthog-go', 'go', ifNull(properties.`$lib`, '') = 'posthog-java', 'java', ifNull(properties.`$lib`, '') = 'posthog-server', 'java', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby', ifNull(properties.`$lib`, '') = 'posthog-python', 'python', 'unknown') AS library,
- count(1) as total
- FROM events_json
- WHERE event = '$exception'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id,
- library
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.25]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.26]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.27]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.28]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.29]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.2]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.30]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.31]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.32]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.33]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.34]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.35]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.36]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.37]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.38]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.39]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.3]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.40]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.41]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.42]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.43]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.44]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.45]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.46]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.47]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.48]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.49]
- '''
-
- SELECT team_id,
- count(1) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND ($group_0 != ''
- OR $group_1 != ''
- OR $group_2 != ''
- OR $group_3 != ''
- OR $group_4 != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.4]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.50]
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(replaceRegexpAll(ifNull(if(toJSONString(properties.^count) != '{}', toJSONString(properties.^count), if(startsWith(dynamicType(properties.count), 'Array')
- OR startsWith(dynamicType(properties.count), 'Map')
- OR startsWith(dynamicType(properties.count), 'Tuple'), toJSONString(properties.count), if(startsWith(dynamicType(properties.count), 'DateTime'), replaceOne(toString(properties.count), ' ', 'T'), toString(properties.count)))), ''), '^"|"$', ''))) as sum
- FROM events_json
- WHERE team_id = 99999
- AND event='decide usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], replaceRegexpAll(ifNull(if(toJSONString(properties.^token) != '{}', toJSONString(properties.^token), if(startsWith(dynamicType(properties.token), 'Array')
- OR startsWith(dynamicType(properties.token), 'Map')
- OR startsWith(dynamicType(properties.token), 'Tuple'), toJSONString(properties.token), if(startsWith(dynamicType(properties.token), 'DateTime'), replaceOne(toString(properties.token), ' ', 'T'), toString(properties.token)))), ''), '^"|"$', ''))
- GROUP BY team
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.51]
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(replaceRegexpAll(ifNull(if(toJSONString(properties.^count) != '{}', toJSONString(properties.^count), if(startsWith(dynamicType(properties.count), 'Array')
- OR startsWith(dynamicType(properties.count), 'Map')
- OR startsWith(dynamicType(properties.count), 'Tuple'), toJSONString(properties.count), if(startsWith(dynamicType(properties.count), 'DateTime'), replaceOne(toString(properties.count), ' ', 'T'), toString(properties.count)))), ''), '^"|"$', ''))) as sum
- FROM events_json
- WHERE team_id = 99999
- AND event='local evaluation usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], replaceRegexpAll(ifNull(if(toJSONString(properties.^token) != '{}', toJSONString(properties.^token), if(startsWith(dynamicType(properties.token), 'Array')
- OR startsWith(dynamicType(properties.token), 'Map')
- OR startsWith(dynamicType(properties.token), 'Tuple'), toJSONString(properties.token), if(startsWith(dynamicType(properties.token), 'DateTime'), replaceOne(toString(properties.token), ' ', 'T'), toString(properties.token)))), ''), '^"|"$', ''))
- GROUP BY team
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.52]
- '''
-
- SELECT team_id,
- COUNT() as count
- FROM events_json
- WHERE event = 'survey sent'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND uuid IN
- (SELECT argMax(uuid, timestamp)
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event = 'survey sent'
- GROUP BY team_id,
- ifNull(properties.`$survey_id`, ''),
- CASE
- WHEN COALESCE(replaceRegexpAll(ifNull(if(toJSONString(properties.^`$survey_submission_id`) != '{}', toJSONString(properties.^`$survey_submission_id`), if(startsWith(dynamicType(properties.`$survey_submission_id`), 'Array')
- OR startsWith(dynamicType(properties.`$survey_submission_id`), 'Map')
- OR startsWith(dynamicType(properties.`$survey_submission_id`), 'Tuple'), toJSONString(properties.`$survey_submission_id`), if(startsWith(dynamicType(properties.`$survey_submission_id`), 'DateTime'), replaceOne(toString(properties.`$survey_submission_id`), ' ', 'T'), toString(properties.`$survey_submission_id`)))), ''), '^"|"$', ''), '') = '' THEN toString(uuid)
- ELSE replaceRegexpAll(ifNull(if(toJSONString(properties.^`$survey_submission_id`) != '{}', toJSONString(properties.^`$survey_submission_id`), if(startsWith(dynamicType(properties.`$survey_submission_id`), 'Array')
- OR startsWith(dynamicType(properties.`$survey_submission_id`), 'Map')
- OR startsWith(dynamicType(properties.`$survey_submission_id`), 'Tuple'), toJSONString(properties.`$survey_submission_id`), if(startsWith(dynamicType(properties.`$survey_submission_id`), 'DateTime'), replaceOne(toString(properties.`$survey_submission_id`), ' ', 'T'), toString(properties.`$survey_submission_id`)))), ''), '^"|"$', '')
- END)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.53]
- '''
-
- SELECT team_id,
- COUNT() - uniqExactIf(request_id, verified
- AND NOT relay
- AND request_id != '') AS count,
- max(relay) AS has_verified_relay
- FROM
- (SELECT team_id,
- replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_gateway_verified`) != '{}', toJSONString(properties.^`$ai_gateway_verified`), if(startsWith(dynamicType(properties.`$ai_gateway_verified`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_gateway_verified`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_gateway_verified`), 'Tuple'), toJSONString(properties.`$ai_gateway_verified`), if(startsWith(dynamicType(properties.`$ai_gateway_verified`), 'DateTime'), replaceOne(toString(properties.`$ai_gateway_verified`), ' ', 'T'), toString(properties.`$ai_gateway_verified`)))), ''), '^"|"$', '') IN ('true',
- '1') AS verified,
- if(verified, replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_gateway_request_id`) != '{}', toJSONString(properties.^`$ai_gateway_request_id`), if(startsWith(dynamicType(properties.`$ai_gateway_request_id`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_gateway_request_id`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_gateway_request_id`), 'Tuple'), toJSONString(properties.`$ai_gateway_request_id`), if(startsWith(dynamicType(properties.`$ai_gateway_request_id`), 'DateTime'), replaceOne(toString(properties.`$ai_gateway_request_id`), ' ', 'T'), toString(properties.`$ai_gateway_request_id`)))), ''), '^"|"$', ''), '') AS request_id,
- if(verified, replaceRegexpAll(ifNull(if(toJSONString(properties.^`$ai_gateway_relay`) != '{}', toJSONString(properties.^`$ai_gateway_relay`), if(startsWith(dynamicType(properties.`$ai_gateway_relay`), 'Array')
- OR startsWith(dynamicType(properties.`$ai_gateway_relay`), 'Map')
- OR startsWith(dynamicType(properties.`$ai_gateway_relay`), 'Tuple'), toJSONString(properties.`$ai_gateway_relay`), if(startsWith(dynamicType(properties.`$ai_gateway_relay`), 'DateTime'), replaceOne(toString(properties.`$ai_gateway_relay`), ' ', 'T'), toString(properties.`$ai_gateway_relay`)))), ''), '^"|"$', ''), '') IN ('true',
- '1') AS relay
- FROM events_json
- WHERE event IN ['$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.54]
- '''
-
- SELECT team_id,
- COUNT() - uniqExactIf(request_id, verified
- AND request_id != '') as count
- FROM
- (SELECT team_id,
- JSONExtractBool(toJSONString(properties), '$ai_gateway_verified') as verified,
- if(verified, JSONExtractString(toJSONString(properties), '$ai_gateway_request_id'), '') as request_id
- FROM events_json
- WHERE event IN ['$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.5]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.6]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.7]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.8]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.9]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema]
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(properties.`$lib`, '') = 'web', 'web_events', ifNull(properties.`$lib`, '') = 'js', 'web_lite_events', ifNull(properties.`$lib`, '') = 'posthog-node', 'node_events', ifNull(properties.`$lib`, '') = 'posthog-edge', 'edge_events', ifNull(properties.`$lib`, '') = 'posthog-convex', 'convex_events', ifNull(properties.`$lib`, '') = 'posthog-android', 'android_events', ifNull(properties.`$lib`, '') = 'posthog-flutter', 'flutter_events', ifNull(properties.`$lib`, '') = 'posthog-ios', 'ios_events', ifNull(properties.`$lib`, '') = 'posthog-go', 'go_events', ifNull(properties.`$lib`, '') = 'posthog-java', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-server', 'java_events', ifNull(properties.`$lib`, '') = 'posthog-react-native', 'react_native_events', ifNull(properties.`$lib`, '') = 'posthog-ruby', 'ruby_events', ifNull(properties.`$lib`, '') = 'posthog-python', 'python_events', ifNull(properties.`$lib`, '') = 'posthog-php', 'php_events', ifNull(properties.`$lib`, '') = 'posthog-dotnet', 'dotnet_events', ifNull(properties.`$lib`, '') = 'posthog-elixir', 'elixir_events', ifNull(properties.`$lib`, '') = 'posthog-unity', 'unity_events', ifNull(properties.`$lib`, '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(properties.`$lib`, '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
diff --git a/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx b/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
index 90cc1d17b0eb..833f1d7b1146 100644
--- a/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
+++ b/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
@@ -64,6 +64,7 @@ export function RetentionBarChart({ inSharedMode = false }: RetentionBarChartPro
getRetentionColor,
} = useValues(retentionGraphLogic(insightProps))
const { openModal } = useActions(retentionModalLogic(insightProps))
+ const { canOpenPersonModal } = useValues(retentionModalLogic(insightProps))
const { aggregationLabel } = useValues(groupsModel)
const selectedInterval = retentionFilter?.selectedInterval ?? null
@@ -71,7 +72,7 @@ export function RetentionBarChart({ inSharedMode = false }: RetentionBarChartPro
const isPercentage = !retentionFilter?.aggregationType || retentionFilter.aggregationType === 'count'
const isIntervalView = selectedInterval !== null
// Shared (public) views don't have the persons modal mounted — disable click-to-open there.
- const canClick = !shouldShowMeanPerBreakdown && !inSharedMode
+ const canClick = !shouldShowMeanPerBreakdown && !inSharedMode && canOpenPersonModal
// Legacy parity: in-progress stroke is line-only.
const series = useMemo(
diff --git a/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx b/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
index de1cd8207e7e..cdd2cbdfe729 100644
--- a/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
+++ b/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
@@ -67,6 +67,7 @@ export function RetentionLineChart({ inSharedMode = false }: RetentionLineChartP
getRetentionColor,
} = useValues(retentionGraphLogic(insightProps))
const { openModal } = useActions(retentionModalLogic(insightProps))
+ const { canOpenPersonModal } = useValues(retentionModalLogic(insightProps))
const { aggregationLabel } = useValues(groupsModel)
const selectedInterval = retentionFilter?.selectedInterval ?? null
@@ -74,7 +75,7 @@ export function RetentionLineChart({ inSharedMode = false }: RetentionLineChartP
const isPercentage = !retentionFilter?.aggregationType || retentionFilter.aggregationType === 'count'
const isIntervalView = selectedInterval !== null
// Shared (public) views don't have the persons modal mounted — disable click-to-open there.
- const canClick = !shouldShowMeanPerBreakdown && !inSharedMode
+ const canClick = !shouldShowMeanPerBreakdown && !inSharedMode && canOpenPersonModal
const series = useMemo(
() =>