Skip to content

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

chore(flags): remove legacy mixed-targeting gate and dead UI paths (#63005)

Gustavo H. Strassburgereade77a6fde3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 1717cba1f186..e38c0d431b76 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4641,7 +4641,7 @@ snapshots:
scenes-app-dashboards--edit--dark:
hash: v1.k794b7964.6d9f86e5e70c5e104354bf716741e81b21cc9335902be2ae193e056e2c99e990.uVpbwD8wdxAgDlmsHN0MnOyVL94S1R-d1LwyzWPX_HE
scenes-app-dashboards--edit--light:
- hash: v1.k794b7964.e322c65d35e800f6823a790bfe6d2a8f0ebec20fedac1bcd32c9854f55396698.L8tsLyZSOxLe87SvV_gu6gHsnN36hJ2DJESAG5IUt2E
+ hash: v1.k794b7964.18e854e3bd5bdc19a13bb395aea436a78509a9fbf12e2d553c3df437abd5db6b.gJAzPLC4weXu0O2-ZaI0lAQouJgoeEQZT7rV4AiB2a8
scenes-app-dashboards--erroring--dark:
hash: v1.k794b7964.a356bf2ce40e53018919ebc890579c0ad6e493385f546d26b1f70471bf99f726.UER3Vv5UUZ1POzJv4_TuxrLBcLfLa8WTZ_hyUX9t72s
scenes-app-dashboards--erroring--light:
@@ -4987,13 +4987,13 @@ snapshots:
scenes-app-feature-flags--feature-flags-list--light:
hash: v1.k794b7964.9f31458f9371ccf1f6ba09cd3728a71c1b1d496b951cc942d6a173d10fa5786d.KAGRvF0AJDFLtof4mRa3aEXUcIc_B0eHSqpDoTHvKws
scenes-app-feature-flags--new-feature-flag--dark:
- hash: v1.k794b7964.b8f6e0b677fa753d25fd9710066d8864cce28c2b8f17e96abd343d91ad72e95c.JX-Y63wT7ojk44kJmYVE9jeRnPRmyMqhkUytg1Opfjo
+ hash: v1.k794b7964.d3ad7126db272d6c5f913b57613dd05c2905ad54dcab5c4f81990db62b8032bd.4uhRQatdSXUiizTQYFr39754aP5csbzqmFOptTht6AE
scenes-app-feature-flags--new-feature-flag--light:
- hash: v1.k794b7964.6070b288eae780b0309d4d4ec6be43299e3a5f75f4d8f99f177967661cba73f9.xasdlli_s76qokmljDu-ZsbB5mF33QA1xjMvGTEhYFM
+ hash: v1.k794b7964.63566204766059c48090fffa57eec90fb5f74ed1cca5af5cce1c7c8a9781b72e.ZRYamuqsGVeQ0nscA25I3oOi_WBdlww-W46LxkHWz5s
scenes-app-feature-flags--new-multivariate-flag-variant-key-error--dark:
- hash: v1.k794b7964.8854deb3501dbeda7f349477f8af77ce618d50cf718e4987c999d2832ce8f53f.c8gUPbguiUSWuR41qtE6ftClF5byUprH4NJKR2TIDw8
+ hash: v1.k794b7964.d3c9931145a8f8ace63ea132512d519d78a85a67dd240f6978275b4cd5b269df.NDuEC4W0EOjPnLDHX5_6ZSy3071842JD3PKOtjXOHks
scenes-app-feature-flags--new-multivariate-flag-variant-key-error--light:
- hash: v1.k794b7964.c7275b6430fbd53565f881d1330f2ea1479f8be838d1ae1689108b3249678f64.h7Ktlbp1VMFYhF6bSwLOS_Jfp_uV71Ia5aQMq9lVDPA
+ hash: v1.k794b7964.b0a781441fb47fa9f7af28aee007358fbb8fe8fc5cd194ca8e5eeb99e592608e.BCH25hWyTwCgoTS6Uh4QqQ0MNU_hwvHzoAGYb6ro-tA
scenes-app-feature-flags--new-remote-config-flag-payload-error--dark:
hash: v1.k794b7964.1af099f2e9f8811e94353c341bcf179757201966841c188ec9e81de48dab7a0b.VbS43TXKb_YBiGph4kYhjf-kfrelIfJT7eUthuLvLhY
scenes-app-feature-flags--new-remote-config-flag-payload-error--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 8a7fb8644dda..c41d3b8d4aa1 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -300,7 +300,6 @@ export const FEATURE_FLAGS = {
FEATURE_FLAG_CREATION_INTENTS: 'feature-flag-creation-intents', // owner: #team-feature-flags
FEATURE_FLAG_DRAG_DROP_CONDITIONS: 'feature-flag-drag-drop-conditions', // owner: @gustavo #team-feature-flags
FEATURE_FLAG_EARLY_EXIT: 'feature-flag-early-exit', // owner: @gustavo #team-feature-flags
- FEATURE_FLAG_MIXED_TARGETING: 'feature-flag-mixed-targeting', // owner: @dmarticus #team-feature-flags
FEATURE_FLAG_NOTIFICATIONS: 'feature-flag-notifications', // owner: @reecejones #team-platform-features
FEATURE_FLAG_USAGE_DASHBOARD_CHECKBOX: 'feature-flag-usage-dashboard-checkbox', // owner: #team-feature-flags, globally disabled, enables opt-out of auto dashboard creation
FIELD_NOTES: 'field-notes', // owner: @adamleith
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
index f01a3c71a651..8036f24d1362 100644
--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx
@@ -102,7 +102,7 @@ const PERSON = 'person' as const
type AggregationValue = number | typeof PERSON
type MatchByOption = {
- value: string
+ value: 'properties' | 'device'
icon: JSX.Element
label: string
description: string
@@ -332,7 +332,6 @@ interface ConditionProps {
taxonomicGroupTypesForCondition: (conditionGroupTypeIndex: number | null | undefined) => TaxonomicFilterGroupType[]
groupTypes: Map<GroupTypeIndex, GroupType>
setConditionAggregation: (index: number, groupTypeIndex: number | null) => void
- isTargetingV2Enabled: boolean
isDeviceTargeting: boolean
onMoveUp: () => void
onMoveDown: () => void
@@ -402,7 +401,6 @@ const ConditionContent = ({
taxonomicGroupTypesForCondition,
groupTypes,
setConditionAggregation,
- isTargetingV2Enabled,
isDeviceTargeting,
onMoveUp,
onMoveDown,
@@ -551,7 +549,7 @@ const ConditionContent = ({
/>
</div>
- {isTargetingV2Enabled && groupTypes.size > 0 && !isDeviceTargeting && (
+ {groupTypes.size > 0 && !isDeviceTargeting && (
<div>
<LemonLabel className="mb-1">Target by</LemonLabel>
<LemonSelect<AggregationValue>
@@ -829,22 +827,16 @@ export function FeatureFlagReleaseConditionsCollapsible({
groupTypes,
openConditions,
properties,
- isMixedTargeting,
isAnyItemDragging,
draggedGroup,
} = useValues(releaseConditionsLogic)
const { featureFlags } = useValues(featureFlagLogic)
const isDragDropEnabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_DRAG_DROP_CONDITIONS]
- // The mixed-targeting flag now gates the unified v2 UI (Properties / Device with full per-condition group-type selector).
- // The legacy 4-card path is reached only when the flag is off.
- const isTargetingV2Enabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_MIXED_TARGETING]
// Ref map for focus management
const optionRefs = useRef<Record<string, HTMLDivElement | null>>({})
- const groupTypeValues = Array.from(groupTypes.values()) as GroupType[]
-
const {
updateConditionSet,
removeConditionSet,
@@ -856,8 +848,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
setAggregationGroupTypeIndex,
setConditionAggregation,
setOpenConditions,
- setIsMixedTargeting,
- switchToMixedTargeting,
setIsAnyItemDragging,
setDraggedGroup,
setEarlyExit,
@@ -959,9 +949,9 @@ export function FeatureFlagReleaseConditionsCollapsible({
const showGroupsOptions = groupTypes.size > 0
const isDeviceTargeting = bucketingIdentifier === FeatureFlagBucketingIdentifier.DEVICE_ID
- const v2MatchByOptions = [
+ const matchByOptions = [
{
- value: 'properties',
+ value: 'properties' as const,
icon: <IconBrackets className="text-base shrink-0" />,
label: 'Properties',
description: showGroupsOptions
@@ -971,7 +961,7 @@ export function FeatureFlagReleaseConditionsCollapsible({
...(onBucketingIdentifierChange
? [
{
- value: 'device',
+ value: 'device' as const,
icon: <IconLaptop className="text-base shrink-0" />,
label: 'Device',
description: 'Stable assignment per device. Good fit for experiments on anonymous users.',
@@ -982,81 +972,17 @@ export function FeatureFlagReleaseConditionsCollapsible({
: []),
] satisfies MatchByOption[]
- const legacyMatchByOptions = [
- {
- value: 'user',
- icon: <IconPerson className="text-base shrink-0" />,
- label: 'User',
- description: 'Stable assignment for logged-in users based on their distinct ID.',
- },
- ...(onBucketingIdentifierChange
- ? [
- {
- value: 'device',
- icon: <IconLaptop className="text-base shrink-0" />,
- label: 'Device',
- description: 'Stable assignment per device. Good fit for experiments on anonymous users.',
- badge: { type: 'warning' as const, text: 'BETA' },
- learnMoreUrl: 'https://posthog.com/docs/feature-flags/device-bucketing',
- },
- ]
- : []),
- ...(showGroupsOptions
- ? [
- {
- value: 'group',
- icon: <IconPeople className="text-base shrink-0" />,
- label: 'Group',
- description:
- 'Stable assignment for everyone in an organization, company, or other custom group type.',
- },
- ]
- : []),
- ] satisfies MatchByOption[]
-
- const matchByOptions: MatchByOption[] = isTargetingV2Enabled ? v2MatchByOptions : legacyMatchByOptions
-
// Compute current selected option (shared between keyboard navigation and selection rendering)
- const currentSelected = isTargetingV2Enabled
- ? isDeviceTargeting && onBucketingIdentifierChange
- ? 'device'
- : 'properties'
- : releaseFilters.aggregation_group_type_index != null
- ? 'group'
- : isDeviceTargeting
- ? 'device'
- : 'user'
+ const currentSelected = isDeviceTargeting && onBucketingIdentifierChange ? 'device' : 'properties'
// Handler for option selection logic (shared by click and keyboard events)
- const selectMatchByOption = (value: string): void => {
- const applyChange = (targetValue: string): void => {
- if (isTargetingV2Enabled) {
- if (targetValue === 'properties') {
- onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DISTINCT_ID)
- } else if (targetValue === 'device') {
- setAggregationGroupTypeIndex(null)
- onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DEVICE_ID)
- }
- return
- }
- if (targetValue === 'user') {
- setIsMixedTargeting(false)
- setAggregationGroupTypeIndex(null)
+ const selectMatchByOption = (value: 'properties' | 'device'): void => {
+ const applyChange = (targetValue: 'properties' | 'device'): void => {
+ if (targetValue === 'properties') {
onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DISTINCT_ID)
} else if (targetValue === 'device') {
- setIsMixedTargeting(false)
setAggregationGroupTypeIndex(null)
onBucketingIdentifierChange?.(FeatureFlagBucketingIdentifier.DEVICE_ID)
- } else if (targetValue === 'group') {
- setIsMixedTargeting(false)
- const firstGroupType = groupTypeValues[0]
- if (firstGroupType) {
- setAggregationGroupTypeIndex(firstGroupType.group_type_index)
- }
- onBucketingIdentifierChange?.(null)
- } else if (targetValue === 'mixed') {
- switchToMixedTargeting()
- onBucketingIdentifierChange?.(null)
}
}
@@ -1126,7 +1052,7 @@ export function FeatureFlagReleaseConditionsCollapsible({
{flagId && <IntentWarningsBanner flagId={flagId} />}
- {!hideMatchOptions && (showGroupsOptions || onBucketingIdentifierChange) && (
+ {!hideMatchOptions && matchByOptions.length > 1 && (
<div>
<LemonLabel
className="mb-2"
@@ -1144,13 +1070,7 @@ export function FeatureFlagReleaseConditionsCollapsible({
// Handle arrow key navigation for radio group
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
e.preventDefault()
- const options = isTargetingV2Enabled
- ? ['properties', ...(onBucketingIdentifierChange ? ['device'] : [])]
- : [
- 'user',
- ...(onBucketingIdentifierChange ? ['device'] : []),
- ...(showGroupsOptions ? ['group'] : []),
- ]
+ const options = matchByOptions.map((option) => option.value)
const currentIndex = options.indexOf(currentSelected)
let nextIndex = currentIndex
@@ -1222,34 +1142,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
</>
)}
</div>
- {/* Group type selector for selected group option */}
- {option.value === 'group' &&
- isSelected &&
- releaseFilters.aggregation_group_type_index != null &&
- !isMixedTargeting &&
- (groupTypeValues.length > 1 ? (
- <div onClick={(e) => e.stopPropagation()}>
- <LemonSelect
- size="xsmall"
- dropdownMatchSelectWidth={false}
- data-attr="feature-flag-group-type-select"
- value={releaseFilters.aggregation_group_type_index}
- onChange={(value) => {
- if (value != null) {
- setAggregationGroupTypeIndex(value)
- }
- }}
- options={groupTypeValues.map((groupType) => ({
- value: groupType.group_type_index,
- label: groupType.group_type,
- }))}
- />
- </div>
- ) : (
- <span className="text-xs font-medium">
- {groupTypeValues[0]?.group_type}
- </span>
- ))}
</div>
</div>
)
@@ -1329,7 +1221,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}
groupTypes={groupTypes}
setConditionAggregation={setConditionAggregation}
- isTargetingV2Enabled={isTargetingV2Enabled}
isDeviceTargeting={isDeviceTargeting}
onMoveUp={() => moveConditionSetUp(index)}
onMoveDown={() => moveConditionSetDown(index)}
@@ -1405,7 +1296,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}
groupTypes={groupTypes}
setConditionAggregation={setConditionAggregation}
- isTargetingV2Enabled={isTargetingV2Enabled}
isDeviceTargeting={isDeviceTargeting}
onMoveUp={() => moveConditionSetUp(index)}
onMoveDown={() => moveConditionSetDown(index)}
@@ -1456,7 +1346,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}
groupTypes={groupTypes}
setConditionAggregation={setConditionAggregation}
- isTargetingV2Enabled={isTargetingV2Enabled}
isDeviceTargeting={isDeviceTargeting}
onMoveUp={() => moveConditionSetUp(index)}
onMoveDown={() => moveConditionSetDown(index)}
@@ -1489,7 +1378,6 @@ export function FeatureFlagReleaseConditionsCollapsible({
taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}
groupTypes={groupTypes}
setConditionAggregation={setConditionAggregation}
- isTargetingV2Enabled={isTargetingV2Enabled}
isDeviceTargeting={isDeviceTargeting}
onMoveUp={() => moveConditionSetUp(index)}
onMoveDown={() => moveConditionSetDown(index)}
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
index 65429e30b23e..c4e6bde5f8c7 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts
@@ -1096,75 +1096,6 @@ describe('the feature flag release conditions logic', () => {
})
})
- it.each([
- {
- name: 'group → mixed',
- initialGlobal: 0 as number | null,
- initialGroups: [
- {
- properties: groupProperties,
- rollout_percentage: 50,
- variant: 'control' as string | null,
- sort_key: 'cond-1',
- description: 'Tech orgs',
- },
- {
- properties: groupProperties,
- rollout_percentage: 100,
- variant: null as string | null,
- sort_key: 'cond-2',
- description: 'All orgs',
- },
- ],
- expectedPerConditionAgg: 0 as number | null,
- },
- {
- name: 'user → mixed',
- initialGlobal: null,
- initialGroups: [
- {
- properties: userProperties,
- rollout_percentage: 75,
- variant: null as string | null,
- sort_key: 'cond-1',
- },
- ],
- expectedPerConditionAgg: null,
- },
- ])(
- 'preserves everything when switching $name',
- async ({ initialGlobal, initialGroups, expectedPerConditionAgg }) => {
- logic?.unmount()
-
- logic = featureFlagReleaseConditionsLogic({
- id: `transition-to-mixed`,
- filters: {
- ...generateFeatureFlagFilters(initialGroups),
- aggregation_group_type_index: initialGlobal,
- },
- })
-
- await expectLogic(logic, () => {
- logic.mount()
- })
-
- await expectLogic(logic, () => {
- logic.actions.switchToMixedTargeting()
- }).toMatchValues({
- isMixedTargeting: true,
- filters: expect.objectContaining({
- aggregation_group_type_index: null,
- groups: initialGroups.map((g) =>
- expect.objectContaining({
- ...g,
- aggregation_group_type_index: expectedPerConditionAgg,
- })
- ),
- }),
- })
- }
- )
-
it.each([
{
name: 'mixed → user',
diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
index cd6f04e463ad..3b6c117b4efd 100644
--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts
@@ -27,7 +27,6 @@ import {
FeatureFlagEvaluationRuntime,
FeatureFlagFilters,
FeatureFlagGroupType,
- GroupType,
GroupTypeIndex,
MultivariateFlagVariant,
PropertyFilterType,
@@ -143,9 +142,6 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
setDistinctIdNames: (distinctIdNames: Record<string, string>) => ({ distinctIdNames }),
setOpenConditions: (openConditions: string[]) => ({ openConditions }),
openCondition: (sortKey: string) => ({ sortKey }),
- setIsMixedTargeting: (isMixedTargeting: boolean) => ({ isMixedTargeting }),
- switchToMixedTargeting: true,
- setMixedGroupTypeIndex: (mixedGroupTypeIndex: number) => ({ mixedGroupTypeIndex }),
setIsAnyItemDragging: (isAnyItemDragging: boolean) => ({ isAnyItemDragging }),
setDraggedGroup: (draggedGroup: FeatureFlagGroupType | null) => ({ draggedGroup }),
}),
@@ -269,22 +265,6 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
}
return { ...state, early_exit: earlyExit }
},
- switchToMixedTargeting: (state) => {
- if (!state) {
- return state
- }
- const previousGlobal = state.aggregation_group_type_index
- return {
- ...state,
- aggregation_group_type_index: null,
- // Each condition inherits the global aggregation type as its
- // per-condition value, so properties remain valid
- groups: state.groups.map((group) => ({
- ...group,
- aggregation_group_type_index: group.aggregation_group_type_index ?? previousGlobal ?? null,
- })) as FeatureFlagGroupTypeWithSortKey[],
- }
- },
setConditionAggregation: (state, { index, groupTypeIndex }) => {
if (!state) {
return state
@@ -404,19 +384,6 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
state.includes(`condition-${sortKey}`) ? state : [...state, `condition-${sortKey}`],
},
],
- isMixedTargeting: [
- false as boolean,
- {
- setIsMixedTargeting: (_, { isMixedTargeting }) => isMixedTargeting,
- switchToMixedTargeting: () => true,
- },
- ],
- mixedGroupTypeIndex: [
- 0 as number,
- {
- setMixedGroupTypeIndex: (_, { mixedGroupTypeIndex }) => mixedGroupTypeIndex,
- },
- ],
isAnyItemDragging: [
false as boolean,
{
@@ -530,9 +497,6 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
actions.setOpenConditions(newOpenConditions)
}
},
- switchToMixedTargeting: () => {
- actions.calculateBlastRadius()
- },
setAggregationGroupTypeIndex: () => {
actions.calculateBlastRadius()
@@ -877,24 +841,6 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
return filterGroups?.flatMap((g) => g.properties ?? []) ?? []
},
],
- hasMixedAggregations: [
- (s) => [s.filterGroups],
- (filterGroups: FeatureFlagGroupType[]) => {
- const aggregations = filterGroups.map((g) => g.aggregation_group_type_index ?? null)
- return aggregations.length > 1 && !aggregations.every((a) => a === aggregations[0])
- },
- ],
- defaultMixedGroupTypeIndex: [
- (s) => [s.filterGroups, s.groupTypes],
- (filterGroups: FeatureFlagGroupType[], groupTypes: Map<GroupTypeIndex, GroupType>) => {
- const groupTypeValues = Array.from(groupTypes.values()) as GroupType[]
- return (
- filterGroups.find((g) => g.aggregation_group_type_index != null)?.aggregation_group_type_index ??
- groupTypeValues[0]?.group_type_index ??
- 0
- )
- },
- ],
}),
propsChanged(({ props, values, actions }) => {
// Compare only the fields that affect release conditions and blast radius,
@@ -932,11 +878,5 @@ export const featureFlagReleaseConditionsLogic = kea<featureFlagReleaseCondition
if (values.filters.groups.length === 1 && values.filters.groups[0]?.sort_key) {
actions.setOpenConditions([`condition-${values.filters.groups[0].sort_key}`])
}
-
- // Initialize mixed targeting state from existing filter groups
- if (values.hasMixedAggregations) {
- actions.setIsMixedTargeting(true)
- }
- actions.setMixedGroupTypeIndex(values.defaultMixedGroupTypeIndex)
}),
])
diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.py
index fcde0eff4e89..5025028c2bd6 100644
--- a/products/feature_flags/backend/api/feature_flag.py
+++ b/products/feature_flags/backend/api/feature_flag.py
@@ -101,7 +101,6 @@ scope_audit_logger = structlog.get_logger("posthog.feature_flag_scope_audit")
BEHAVIOURAL_COHORT_FOUND_ERROR_CODE = "behavioral_cohort_found"
REALTIME_COHORT_FLAG_TARGETING_FLAG = "realtime-cohort-flag-targeting"
-MIXED_TARGETING_FLAG = "feature-flag-mixed-targeting"
EARLY_EXIT_FLAG = "feature-flag-early-exit"
# Fields that Rust's FeatureFlag struct expects for historical evaluation
@@ -1064,12 +1063,6 @@ class FeatureFlagSerializer(
if all(a == condition_aggregations[0] for a in condition_aggregations):
filters["aggregation_group_type_index"] = condition_aggregations[0]
else:
- if not self._is_mixed_targeting_enabled():
- raise serializers.ValidationError(
- "Mixed aggregation types across condition sets are not yet supported. "
- "All condition sets must use the same aggregation type.",
- code="invalid_input",
- )
filters["aggregation_group_type_index"] = None
# Check Early Access Feature constraint: no condition set can use group
@@ -1372,26 +1365,6 @@ class FeatureFlagSerializer(
dependencies.add(flag_key)
return dependencies
- def _is_mixed_targeting_enabled(self) -> bool:
- try:
- request = self.context.get("request")
- if not request:
- return False
- user = getattr(request, "user", None)
- if user is None or user.is_anonymous:
- return False
- return posthoganalytics.feature_enabled(
- MIXED_TARGETING_FLAG,
- user.distinct_id,
- groups={"organization": str(user.organization.id)},
- group_properties={"organization": {"id": str(user.organization.id)}},
- only_evaluate_locally=False,
- send_feature_flag_events=False,
- )
- except Exception:
- logger.exception("Failed to check mixed targeting flag")
- return False
-
def _is_early_exit_enabled(self) -> bool:
try:
request = self.context.get("request")
diff --git a/products/feature_flags/backend/api/test/test_feature_flag.py b/products/feature_flags/backend/api/test/test_feature_flag.py
index c62660d0c276..1b993969d32b 100644
--- a/products/feature_flags/backend/api/test/test_feature_flag.py
+++ b/products/feature_flags/backend/api/test/test_feature_flag.py
@@ -5008,26 +5008,7 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
},
)
- @parameterized.expand(
- [
- (
- "flag_enabled",
- True,
- status.HTTP_201_CREATED,
- ),
- (
- "flag_disabled",
- False,
- status.HTTP_400_BAD_REQUEST,
- ),
- ]
- )
- @patch("products.feature_flags.backend.api.feature_flag.posthoganalytics.feature_enabled")
- def test_mixed_aggregation_types_across_condition_sets(
- self, _name, mixed_targeting_enabled, expected_status, mock_feature_enabled
- ):
- mock_feature_enabled.return_value = mixed_targeting_enabled
-
+ def test_mixed_aggregation_types_across_condition_sets(self):
GroupTypeMapping.objects.create(
team=self.team, project_id=self.team.project_id, group_type="organization", group_type_index=0
)
@@ -5054,22 +5035,16 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
},
format="json",
)
- self.assertEqual(response.status_code, expected_status)
-
- if expected_status == status.HTTP_201_CREATED:
- # Flag-level aggregation is None when condition sets have mixed aggregation types
- self.assertIsNone(response.json()["filters"]["aggregation_group_type_index"])
- # Each condition set retains its own aggregation type
- groups = response.json()["filters"]["groups"]
- self.assertIsNone(groups[0]["aggregation_group_type_index"])
- self.assertEqual(groups[1]["aggregation_group_type_index"], 0)
- else:
- self.assertIn("Mixed aggregation types", response.json()["detail"])
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- @patch("products.feature_flags.backend.api.feature_flag.posthoganalytics.feature_enabled")
- def test_mixed_aggregation_round_trip(self, mock_feature_enabled):
- mock_feature_enabled.return_value = True
+ # Flag-level aggregation is None when condition sets have mixed aggregation types
+ self.assertIsNone(response.json()["filters"]["aggregation_group_type_index"])
+ # Each condition set retains its own aggregation type
+ groups = response.json()["filters"]["groups"]
+ self.assertIsNone(groups[0]["aggregation_group_type_index"])
+ self.assertEqual(groups[1]["aggregation_group_type_index"], 0)
+ def test_mixed_aggregation_round_trip(self):
GroupTypeMapping.objects.create(
team=self.team, project_id=self.team.project_id, group_type="organization", group_type_index=0
)
@@ -5097,18 +5072,7 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
self.assertIsNone(filters["groups"][0]["aggregation_group_type_index"])
self.assertEqual(filters["groups"][1]["aggregation_group_type_index"], 0)
- @parameterized.expand(
- [
- ("flag_enabled", True, status.HTTP_201_CREATED),
- ("flag_disabled", False, status.HTTP_400_BAD_REQUEST),
- ]
- )
- @patch("products.feature_flags.backend.api.feature_flag.posthoganalytics.feature_enabled")
- def test_mixed_aggregation_with_properties(
- self, _name, mixed_targeting_enabled, expected_status, mock_feature_enabled
- ):
- mock_feature_enabled.return_value = mixed_targeting_enabled
-
+ def test_mixed_aggregation_with_properties(self):
GroupTypeMapping.objects.create(
team=self.team, project_id=self.team.project_id, group_type="organization", group_type_index=0
)
@@ -5145,30 +5109,18 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
},
format="json",
)
- self.assertEqual(response.status_code, expected_status)
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- if expected_status == status.HTTP_201_CREATED:
- groups = response.json()["filters"]["groups"]
- self.assertIsNone(groups[0]["aggregation_group_type_index"])
- self.assertEqual(groups[1]["aggregation_group_type_index"], 0)
- else:
- self.assertIn("Mixed aggregation types", response.json()["detail"])
-
- @parameterized.expand(
- [
- ("flag_enabled", True, status.HTTP_200_OK),
- ("flag_disabled", False, status.HTTP_400_BAD_REQUEST),
- ]
- )
- @patch("products.feature_flags.backend.api.feature_flag.posthoganalytics.feature_enabled")
- def test_patch_uniform_flag_to_mixed(self, _name, mixed_targeting_enabled, expected_status, mock_feature_enabled):
- mock_feature_enabled.return_value = mixed_targeting_enabled
+ groups = response.json()["filters"]["groups"]
+ self.assertIsNone(groups[0]["aggregation_group_type_index"])
+ self.assertEqual(groups[1]["aggregation_group_type_index"], 0)
+ def test_patch_uniform_flag_to_mixed(self):
GroupTypeMapping.objects.create(
team=self.team, project_id=self.team.project_id, group_type="organization", group_type_index=0
)
- # Create a uniform person-aggregated flag (no feature flag check needed for uniform)
+ # Create a uniform person-aggregated flag
flag = FeatureFlag.objects.create(
team=self.team,
key="uniform-to-mixed",
@@ -5193,7 +5145,14 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
},
format="json",
)
- self.assertEqual(response.status_code, expected_status)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ # Flag-level aggregation collapses to None once condition sets are mixed
+ filters = response.json()["filters"]
+ self.assertIsNone(filters["aggregation_group_type_index"])
+ # Each condition set retains its own aggregation type
+ self.assertIsNone(filters["groups"][0]["aggregation_group_type_index"])
+ self.assertEqual(filters["groups"][1]["aggregation_group_type_index"], 0)
def test_per_condition_aggregation_normalization(self):
"""Test that flag-level aggregation is distributed to condition sets without one"""
diff --git a/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr b/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr
index 806cfa5e8103..2d50b51324d2 100644
--- a/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr
+++ b/products/product_analytics/backend/hogql_queries/paths/test/__snapshots__/test_paths_query_runner_ee.ambr
@@ -3510,6 +3510,570 @@
use_hive_partitioning=0
'''
# ---
+# name: TestClickhousePaths.test_recording_with_start_and_end
+ '''
+ SELECT persons.id AS id,
+ persons.created_at AS created_at,
+ source.event_count AS event_count,
+ source.matching_events AS matching_events
+ FROM (
+ SELECT person_id AS actor_id,
+ groupUniqArray(100)(tuple(timestamp, uuid,
+ session_id,
+ window_id)) AS matching_events,
+ count(*) AS event_count
+ FROM (
+ SELECT person_id AS person_id,
+ path AS path,
+ conversion_time AS conversion_time,
+ event_in_session_index AS event_in_session_index,
+ concat(ifNull(toString(event_in_session_index), ''), '_',
+ ifNull(toString(path), '')) AS path_key,
+ if(ifNull(greater(event_in_session_index,
+ 1), 0), concat(ifNull(toString(minus(event_in_session_index,
+ 1)), ''), '_',
+ ifNull(toString(prev_path), '')), NULL) AS last_path_key,
+ path_dropoff_key AS path_dropoff_key,
+ final_uuid AS uuid,
+ final_timestamp AS timestamp,
+ final_session_id AS session_id,
+ final_window_id AS window_id
+ FROM (
+ SELECT person_id AS person_id,
+ joined_path_tuple.1 AS path,
+ joined_path_tuple.2 AS conversion_time,
+ joined_path_tuple.3 AS prev_path,
+ event_in_session_index,
+ session_index AS session_index,
+ arrayPopFront(arrayPushBack(path_basic,
+ '')) AS path_basic_0,
+ arrayMap((x,
+ y) -> if(ifNull(equals(x,
+ y), isNull(x)
+ and isNull(y)), 0,
+ 1), path_basic,
+ path_basic_0) AS mapping,
+ arrayFilter((x,
+ y) -> y,
+ time,
+ mapping) AS timings,
+ arrayFilter((x,
+ y) -> y,
+ path_basic,
+ mapping) AS compact_path,
+ indexOf(compact_path,
+ '/3') AS target_index,
+ joined_path_tuple.4 AS final_uuid,
+ joined_path_tuple.5 AS final_timestamp,
+ joined_path_tuple.6 AS final_session_id,
+ joined_path_tuple.7 AS final_window_id,
+ arrayFilter((x,
+ y) -> y,
+ uuid_items,
+ mapping) AS uuid,
+ arrayFilter((x,
+ y) -> y,
+ timestamp_items,
+ mapping) AS timestamp,
+ arrayFilter((x,
+ y) -> y,
+ session_id_items,
+ mapping) AS session_id,
+ arrayFilter((x,
+ y) -> y,
+ window_id_items,
+ mapping) AS window_id,
+ indexOf(compact_path,
+ '/1') AS start_target_index,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(compact_path,
+ start_target_index), compact_path) AS start_filtered_path,
+ indexOf(start_filtered_path,
+ '/3') AS end_target_index,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_path,
+ end_target_index), start_filtered_path) AS filtered_path,
+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,
+ 1,
+ intDiv(5,
+ 2)), ['...'],
+ arraySlice(filtered_path,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_path) AS limited_path,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(timings,
+ start_target_index), timings) AS start_filtered_timings,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_timings,
+ end_target_index), start_filtered_timings) AS filtered_timings,
+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,
+ 1,
+ intDiv(5,
+ 2)), [filtered_timings[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_timings,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_timings) AS limited_timings,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(uuid,
+ start_target_index), uuid) AS start_filtered_uuid,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_uuid,
+ end_target_index), start_filtered_uuid) AS filtered_uuid,
+ if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,
+ 1,
+ intDiv(5,
+ 2)), [filtered_uuid[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_uuid,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_uuid) AS limited_uuid,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_timestamp,
+ end_target_index), start_filtered_timestamp) AS filtered_timestamp,
+ if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,
+ 1,
+ intDiv(5,
+ 2)), [filtered_timestamp[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_timestamp,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_timestamp) AS limited_timestamp,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(session_id,
+ start_target_index), session_id) AS start_filtered_session_id,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_session_id,
+ end_target_index), start_filtered_session_id) AS filtered_session_id,
+ if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,
+ 1,
+ intDiv(5,
+ 2)), [filtered_session_id[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_session_id,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_session_id) AS limited_session_id,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(window_id,
+ start_target_index), window_id) AS start_filtered_window_id,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_window_id,
+ end_target_index), start_filtered_window_id) AS filtered_window_id,
+ if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,
+ 1,
+ intDiv(5,
+ 2)), [filtered_window_id[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_window_id,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_window_id) AS limited_window_id,
+ arrayDifference(limited_timings) AS timings_diff,
+ concat(ifNull(toString(length(limited_path)), ''), '_',
+ ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,
+ arrayZip(limited_path,
+ timings_diff,
+ arrayPopBack(arrayPushFront(limited_path,
+ '')), limited_uuid,
+ limited_timestamp,
+ limited_session_id,
+ limited_window_id) AS limited_path_timings
+ FROM (
+ SELECT person_id AS person_id,
+ path_time_tuple.1 AS path_basic,
+ path_time_tuple.2 AS time,
+ session_index,
+ arrayZip(path_list,
+ timing_list,
+ arrayDifference(timing_list), uuid_list,
+ timestamp_list,
+ session_id_list,
+ window_id_list) AS paths_tuple,
+ arraySplit(x -> if(ifNull(less(x.3,
+ 1800), 0), 0,
+ 1), paths_tuple) AS session_paths,
+ path_time_tuple.4 AS uuid_items,
+ path_time_tuple.5 AS timestamp_items,
+ path_time_tuple.6 AS session_id_items,
+ path_time_tuple.7 AS window_id_items
+ FROM (
+ SELECT person_id AS person_id,
+ groupArray(timestamp) AS timing_list,
+ groupArray(path_item) AS path_list,
+ groupArray(uuid) AS uuid_list,
+ groupArray(timestamp) AS timestamp_list,
+ groupArray(session_id) AS session_id_list,
+ groupArray(window_id) AS window_id_list
+ FROM (
+ SELECT toTimeZone(events.timestamp,
+ 'UTC') AS timestamp,
+ if(not(empty(events__override.distinct_id)), events__override.person_id,
+ events.person_id) AS person_id,
+ ifNull(if(equals(events.event,
+ '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,
+ '$current_url'), ''), 'null'), '^"|"$',
+ ''), ''), '(.)/$',
+ '\\1'), events.event), '') AS path_item_ungrouped,
+ events.uuid AS uuid,
+ toTimeZone(events.timestamp,
+ 'UTC') AS timestamp,
+ ifNull(nullIf(nullIf(events.`$session_id`,
+ ''), 'null'), '') AS session_id,
+ ifNull(nullIf(nullIf(events.`$window_id`,
+ ''), 'null'), '') AS window_id,
+ NULL AS groupings,
+ multiMatchAnyIndex(path_item_ungrouped,
+ NULL) AS group_index, (if(ifNull(greater(group_index,
+ 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item
+ FROM events
+ LEFT OUTER JOIN (
+ SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides
+ WHERE equals(person_distinct_id_overrides.team_id,
+ 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,
+ events__override.distinct_id)
+ WHERE and(equals(events.team_id,
+ 99999), and(greaterOrEquals(events.timestamp,
+ toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',
+ 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,
+ assumeNotNull(toDateTime('2012-01-02 23:59:59',
+ 'UTC')))), equals(events.event,
+ '$pageview'))
+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,
+ events.person_id) ASC, toTimeZone(events.timestamp,
+ 'UTC') ASC)
+ GROUP BY person_id) ARRAY
+ JOIN session_paths AS path_time_tuple,
+ arrayEnumerate(session_paths) AS session_index) ARRAY
+ JOIN limited_path_timings AS joined_path_tuple,
+ arrayEnumerate(limited_path_timings) AS event_in_session_index
+ WHERE and(ifNull(greater(start_target_index,
+ 0), 0), ifNull(greater(end_target_index,
+ 0), 0)))) WHERE equals(path_key,
+ '2_/2')
+ GROUP BY person_id) AS source
+ INNER JOIN (
+ SELECT tupleElement(argMax(tuple(toTimeZone(person.created_at,
+ 'UTC')), person.version), 1) AS created_at,
+ person.id AS id
+ FROM person
+ WHERE and(equals(person.team_id,
+ 99999), in(id, (
+ SELECT source.actor_id AS actor_id
+ FROM (
+ SELECT person_id AS actor_id,
+ groupUniqArray(100)(tuple(timestamp, uuid,
+ session_id,
+ window_id)) AS matching_events,
+ count(*) AS event_count
+ FROM (
+ SELECT person_id AS person_id,
+ path AS path,
+ conversion_time AS conversion_time,
+ event_in_session_index AS event_in_session_index,
+ concat(ifNull(toString(event_in_session_index), ''), '_',
+ ifNull(toString(path), '')) AS path_key,
+ if(ifNull(greater(event_in_session_index,
+ 1), 0), concat(ifNull(toString(minus(event_in_session_index,
+ 1)), ''), '_',
+ ifNull(toString(prev_path), '')), NULL) AS last_path_key,
+ path_dropoff_key AS path_dropoff_key,
+ final_uuid AS uuid,
+ final_timestamp AS timestamp,
+ final_session_id AS session_id,
+ final_window_id AS window_id
+ FROM (
+ SELECT person_id AS person_id,
+ joined_path_tuple.1 AS path,
+ joined_path_tuple.2 AS conversion_time,
+ joined_path_tuple.3 AS prev_path,
+ event_in_session_index,
+ session_index AS session_index,
+ arrayPopFront(arrayPushBack(path_basic,
+ '')) AS path_basic_0,
+ arrayMap((x,
+ y) -> if(ifNull(equals(x,
+ y), isNull(x)
+ and isNull(y)), 0,
+ 1), path_basic,
+ path_basic_0) AS mapping,
+ arrayFilter((x,
+ y) -> y,
+ time,
+ mapping) AS timings,
+ arrayFilter((x,
+ y) -> y,
+ path_basic,
+ mapping) AS compact_path,
+ indexOf(compact_path,
+ '/3') AS target_index,
+ joined_path_tuple.4 AS final_uuid,
+ joined_path_tuple.5 AS final_timestamp,
+ joined_path_tuple.6 AS final_session_id,
+ joined_path_tuple.7 AS final_window_id,
+ arrayFilter((x,
+ y) -> y,
+ uuid_items,
+ mapping) AS uuid,
+ arrayFilter((x,
+ y) -> y,
+ timestamp_items,
+ mapping) AS timestamp,
+ arrayFilter((x,
+ y) -> y,
+ session_id_items,
+ mapping) AS session_id,
+ arrayFilter((x,
+ y) -> y,
+ window_id_items,
+ mapping) AS window_id,
+ indexOf(compact_path,
+ '/1') AS start_target_index,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(compact_path,
+ start_target_index), compact_path) AS start_filtered_path,
+ indexOf(start_filtered_path,
+ '/3') AS end_target_index,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_path,
+ end_target_index), start_filtered_path) AS filtered_path,
+ if(ifNull(greater(length(filtered_path), 5), 0), arrayConcat(arraySlice(filtered_path,
+ 1,
+ intDiv(5,
+ 2)), ['...'],
+ arraySlice(filtered_path,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_path) AS limited_path,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(timings,
+ start_target_index), timings) AS start_filtered_timings,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_timings,
+ end_target_index), start_filtered_timings) AS filtered_timings,
+ if(ifNull(greater(length(filtered_timings), 5), 0), arrayConcat(arraySlice(filtered_timings,
+ 1,
+ intDiv(5,
+ 2)), [filtered_timings[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_timings,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_timings) AS limited_timings,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(uuid,
+ start_target_index), uuid) AS start_filtered_uuid,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_uuid,
+ end_target_index), start_filtered_uuid) AS filtered_uuid,
+ if(ifNull(greater(length(filtered_uuid), 5), 0), arrayConcat(arraySlice(filtered_uuid,
+ 1,
+ intDiv(5,
+ 2)), [filtered_uuid[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_uuid,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_uuid) AS limited_uuid,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(timestamp, start_target_index), timestamp) AS start_filtered_timestamp,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_timestamp,
+ end_target_index), start_filtered_timestamp) AS filtered_timestamp,
+ if(ifNull(greater(length(filtered_timestamp), 5), 0), arrayConcat(arraySlice(filtered_timestamp,
+ 1,
+ intDiv(5,
+ 2)), [filtered_timestamp[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_timestamp,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_timestamp) AS limited_timestamp,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(session_id,
+ start_target_index), session_id) AS start_filtered_session_id,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_session_id,
+ end_target_index), start_filtered_session_id) AS filtered_session_id,
+ if(ifNull(greater(length(filtered_session_id), 5), 0), arrayConcat(arraySlice(filtered_session_id,
+ 1,
+ intDiv(5,
+ 2)), [filtered_session_id[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_session_id,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_session_id) AS limited_session_id,
+ if(ifNull(greater(start_target_index,
+ 0), 0), arraySlice(window_id,
+ start_target_index), window_id) AS start_filtered_window_id,
+ if(ifNull(greater(end_target_index,
+ 0), 0), arrayResize(start_filtered_window_id,
+ end_target_index), start_filtered_window_id) AS filtered_window_id,
+ if(ifNull(greater(length(filtered_window_id), 5), 0), arrayConcat(arraySlice(filtered_window_id,
+ 1,
+ intDiv(5,
+ 2)), [filtered_window_id[plus(1,
+ intDiv(5,
+ 2))]], arraySlice(filtered_window_id,
+ multiply(-1,
+ intDiv(5,
+ 2)), intDiv(5,
+ 2))), filtered_window_id) AS limited_window_id,
+ arrayDifference(limited_timings) AS timings_diff,
+ concat(ifNull(toString(length(limited_path)), ''), '_',
+ ifNull(toString(limited_path[-1]), '')) AS path_dropoff_key,
+ arrayZip(limited_path,
+ timings_diff,
+ arrayPopBack(arrayPushFront(limited_path,
+ '')), limited_uuid,
+ limited_timestamp,
+ limited_session_id,
+ limited_window_id) AS limited_path_timings
+ FROM (
+ SELECT person_id AS person_id,
+ path_time_tuple.1 AS path_basic,
+ path_time_tuple.2 AS time,
+ session_index,
+ arrayZip(path_list,
+ timing_list,
+ arrayDifference(timing_list), uuid_list,
+ timestamp_list,
+ session_id_list,
+ window_id_list) AS paths_tuple,
+ arraySplit(x -> if(ifNull(less(x.3,
+ 1800), 0), 0,
+ 1), paths_tuple) AS session_paths,
+ path_time_tuple.4 AS uuid_items,
+ path_time_tuple.5 AS timestamp_items,
+ path_time_tuple.6 AS session_id_items,
+ path_time_tuple.7 AS window_id_items
+ FROM (
+ SELECT person_id AS person_id,
+ groupArray(timestamp) AS timing_list,
+ groupArray(path_item) AS path_list,
+ groupArray(uuid) AS uuid_list,
+ groupArray(timestamp) AS timestamp_list,
+ groupArray(session_id) AS session_id_list,
+ groupArray(window_id) AS window_id_list
+ FROM (
+ SELECT toTimeZone(events.timestamp,
+ 'UTC') AS timestamp,
+ if(not(empty(events__override.distinct_id)), events__override.person_id,
+ events.person_id) AS person_id,
+ ifNull(if(equals(events.event,
+ '$pageview'), replaceRegexpAll(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties,
+ '$current_url'), ''), 'null'), '^"|"$',
+ ''), ''), '(.)/$',
+ '\\1'), events.event), '') AS path_item_ungrouped,
+ events.uuid AS uuid,
+ toTimeZone(events.timestamp,
+ 'UTC') AS timestamp,
+ ifNull(nullIf(nullIf(events.`$session_id`,
+ ''), 'null'), '') AS session_id,
+ ifNull(nullIf(nullIf(events.`$window_id`,
+ ''), 'null'), '') AS window_id,
+ NULL AS groupings,
+ multiMatchAnyIndex(path_item_ungrouped,
+ NULL) AS group_index, (if(ifNull(greater(group_index,
+ 0), 0), groupings[group_index], path_item_ungrouped) AS path_item) AS path_item
+ FROM events
+ LEFT OUTER JOIN (
+ SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
+ person_distinct_id_overrides.distinct_id AS distinct_id
+ FROM person_distinct_id_overrides WHERE equals(person_distinct_id_overrides.team_id,
+ 99999)
+ GROUP BY person_distinct_id_overrides.distinct_id
+ HAVING equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id,
+ events__override.distinct_id)
+ WHERE and(equals(events.team_id,
+ 99999), and(greaterOrEquals(events.timestamp,
+ toStartOfInterval(assumeNotNull(toDateTime('2012-01-01 00:00:00',
+ 'UTC')), toIntervalDay(1))), lessOrEquals(events.timestamp,
+ assumeNotNull(toDateTime('2012-01-02 23:59:59',
+ 'UTC')))), equals(events.event,
+ '$pageview'))
+ ORDER BY if(not(empty(events__override.distinct_id)), events__override.person_id,
+ events.person_id) ASC, toTimeZone(events.timestamp,
+ 'UTC') ASC)
+ GROUP BY person_id) ARRAY
+ JOIN session_paths AS path_time_tuple,
+ arrayEnumerate(session_paths) AS session_index) ARRAY
+ JOIN limited_path_timings AS joined_path_tuple,
+ arrayEnumerate(limited_path_timings) AS event_in_session_index
+ WHERE and(ifNull(greater(start_target_index,
+ 0), 0), ifNull(greater(end_target_index,
+ 0), 0)))) WHERE equals(path_key,
+ '2_/2')
+ GROUP BY person_id) AS source)))
+ GROUP BY person.id
+ HAVING and(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), less(tupleElement(argMax(tuple(toTimeZone(person.created_at,
+ 'UTC')), person.version), 1), plus(now64(6,
+ 'UTC'), toIntervalDay(1)))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id,
+ source.actor_id)
+ ORDER BY persons.id ASC
+ LIMIT 101
+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,
+ join_algorithm='auto',
+ readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
+# name: TestClickhousePaths.test_recording_with_start_and_end.1
+ '''
+ SELECT session_replay_events.session_id AS session_id,
+ min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,
+ max(session_replay_events.retention_period_days) AS retention_period_days,
+ plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time
+ FROM session_replay_events
+ WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['s1']))
+ GROUP BY session_replay_events.session_id
+ HAVING and(greaterOrEquals(expiry_time, toDateTime64('2012-01-01 03:21:34.000000', 6, 'UTC')), equals(max(session_replay_events.is_deleted), 0))
+ LIMIT 100 SETTINGS readonly=2,
+ max_execution_time=60,
+ allow_experimental_object_type=1,
+ max_ast_elements=4000000,
+ max_expanded_ast_elements=4000000,
+ max_bytes_before_external_group_by=0,
+ transform_null_in=1,
+ optimize_min_equality_disjunction_chain_length=4294967295,
+ optimize_rewrite_aggregate_function_with_if=0,
+ optimize_min_inequality_conjunction_chain_length=4294967295,
+ allow_experimental_join_condition=1,
+ use_hive_partitioning=0
+ '''
+# ---
# name: TestClickhousePaths.test_respect_session_limits
'''
SELECT last_path_key AS source_event,