:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): Coerce string properties to float for ordered numeric filters (#111714)
Juraj Majerik388a061dad60
diff --git a/common/hogvm/python/stl/__init__.py b/common/hogvm/python/stl/__init__.pyindex ce573606c1dc..dffde88be173 100644--- a/common/hogvm/python/stl/__init__.py+++ b/common/hogvm/python/stl/__init__.py@@ -90,7 +90,8 @@ def toInt(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]],datetime.datetime(args[0]["year"], args[0]["month"], args[0]["day"]) - datetime.datetime(1970, 1, 1)).daysreturn int(args[0])- except ValueError:+ # TypeError covers null and other unconvertible types; the TS and Rust VMs return null for those too.+ except (TypeError, ValueError):return None@@ -105,7 +106,8 @@ def toFloat(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]]).days)return float(args[0])- except ValueError:+ # TypeError covers null and other unconvertible types; the TS and Rust VMs return null for those too.+ except (TypeError, ValueError):return Nonediff --git a/common/hogvm/python/test/test_execute.py b/common/hogvm/python/test/test_execute.pyindex 2ad1d01f771b..8b615edce355 100644--- a/common/hogvm/python/test/test_execute.py+++ b/common/hogvm/python/test/test_execute.py@@ -113,8 +113,10 @@ class TestBytecodeExecute:assert self._run("toString('string')") == "string"assert self._run("toInt('1')") == 1assert self._run("toInt('bla')") is None+ assert self._run("toInt(null)") is Noneassert self._run("toFloat('1.2')") == 1.2assert self._run("toFloat('bla')") is None+ assert self._run("toFloat(null)") is Noneassert self._run("toUUID('asd')") == "asd"assert self._run("1 == null") is Falseassert self._run("1 != null") is Truediff --git a/posthog/cdp/test/test_filters.py b/posthog/cdp/test/test_filters.pyindex 5d5f7aa49cb6..710a13c04670 100644--- a/posthog/cdp/test/test_filters.py+++ b/posthog/cdp/test/test_filters.py@@ -89,6 +89,26 @@ class TestHogFunctionFilters(ClickhouseTestMixin, APIBaseTest, QueryMatchingTestassert bytecode == ["_H", HOGQL_BYTECODE_VERSION, 29]assert execute_bytecode(bytecode, {}).result is True+ @parameterized.expand(+ [+ ("missing_property", {}),+ ("null_property", {"score": None}),+ ]+ )+ def test_ordered_numeric_filter_bytecode_handles_missing_property(self, _name, properties):+ # An ordered numeric filter on an untyped property compiles to a toFloat(...) cast. The+ # Python VM raised TypeError on a missing or null property, which made error tracking+ # alert filtering fail closed and suppress alerts a negated filter should pass.+ bytecode = self.filters_to_bytecode(+ filters={"properties": [{"key": "score", "operator": "not_between", "value": [0, 100], "type": "event"}]}+ )+ assert execute_bytecode(bytecode, {"properties": properties}).result is True++ bytecode = self.filters_to_bytecode(+ filters={"properties": [{"key": "score", "operator": "gt", "value": 0, "type": "event"}]}+ )+ assert execute_bytecode(bytecode, {"properties": properties}).result is False+def test_filters_all_events(self):bytecode = self.filters_to_bytecode(filters={diff --git a/posthog/hogql/property.py b/posthog/hogql/property.pyindex 95cc9b9eb627..294664e803b7 100644--- a/posthog/hogql/property.py+++ b/posthog/hogql/property.py@@ -434,33 +434,24 @@ def _handle_bool_values(value: ValueT, expr: ast.Expr, property: Property, team:return value-def _coerce_numeric_value_for_string_property(value: ValueT, property: Property, team: Team) -> ValueT:- """Person, event, and group properties are pulled out of JSON as strings, so a numeric- filter value against a string-typed one compiles to equals(<String>, <number>), which- ClickHouse rejects with NO_COMMON_TYPE. Stringify the numeric value in that case,- mirroring _stringify_group_key_value for group keys.+# bool is a subclass of int — exclude it so booleans keep flowing through _handle_bool_values+def _is_numeric_filter_value(v: object) -> bool:+ return not isinstance(v, bool) and isinstance(v, (int, float))- Numeric-, Boolean-, and DateTime-typed properties are cast to a Float / Bool / DateTime- LHS by PropertySwapper, so their comparisons already resolve to a common type — those are- left untouched (stringifying them would reintroduce the mismatch the other way around).- Only the narrow numeric-value-vs-string-property shape is coerced.- Accepts a scalar or a list of values; the type lookup runs at most once either way."""-- # bool is a subclass of int — exclude it so booleans keep flowing through _handle_bool_values- def _is_numeric(v: object) -> bool:- return not isinstance(v, bool) and isinstance(v, (int, float))-- values = value if isinstance(value, list) else [value]- if not any(_is_numeric(v) for v in values):- return value+def _property_lhs_stays_string(property: Property, team: Team) -> bool:+ """Whether the property's LHS compiles to a JSON-extracted String.+ Numeric-, Boolean-, and DateTime-typed properties are cast to a Float / Bool / DateTime+ LHS by PropertySwapper, so their comparisons already resolve to a common type.+ A String-typed or as-yet-undefined property keeps its String LHS, and a numeric+ comparison against it needs coercion on one side or the other."""# map_virtual_properties rewrites a $virt_ key to a typed column on the parent table instead# of a JSON extract, so its LHS is already numeric and has no PropertyDefinition row to look- # up. Without this guard the lookup below misses and stringifies, which breaks numeric virtual+ # up. Without this guard the lookup below misses and coerces, which breaks numeric virtual# properties such as $virt_revenue.if property.key and property.key.startswith("$virt_"):- return value+ return Falseif property.type == "person":type_filters: dict[str, object] = {"type": PropertyDefinition.Type.PERSON}@@ -473,7 +464,7 @@ def _coerce_numeric_value_for_string_property(value: ValueT, property: Property,else:# Other property types (session, data warehouse, logs, spans, …) resolve to properly# typed columns, so a numeric comparison already has a common type — leave them alone.- return value+ return Falseproperty_type = (PropertyDefinition.objects.alias(@@ -488,13 +479,29 @@ def _coerce_numeric_value_for_string_property(value: ValueT, property: Property,.first())- if property_type in (PropertyType.Numeric, PropertyType.Boolean, PropertyType.Datetime):+ return property_type not in (PropertyType.Numeric, PropertyType.Boolean, PropertyType.Datetime)+++def _coerce_numeric_value_for_string_property(value: ValueT, property: Property, team: Team) -> ValueT:+ """Person, event, and group properties are pulled out of JSON as strings, so a numeric+ filter value against a string-typed one compiles to equals(<String>, <number>), which+ ClickHouse rejects with NO_COMMON_TYPE. Stringify the numeric value in that case,+ mirroring _stringify_group_key_value for group keys.++ Only the narrow numeric-value-vs-string-property shape is coerced; a typed LHS is+ left untouched (stringifying it would reintroduce the mismatch the other way around).++ Accepts a scalar or a list of values; the type lookup runs at most once either way."""+ values = value if isinstance(value, list) else [value]+ if not any(_is_numeric_filter_value(v) for v in values):+ return value++ if not _property_lhs_stays_string(property, team):return value- # String-typed or as-yet-undefined property: the LHS stays a JSON-extracted String, so- # stringify to keep both sides comparable. An integer-valued float loses its '.0' (13.0 -> '13').+ # An integer-valued float loses its '.0' (13.0 -> '13').def _stringify(v: object) -> object:- if not _is_numeric(v):+ if not _is_numeric_filter_value(v):return vif isinstance(v, float) and v.is_integer():return str(int(v))@@ -505,6 +512,43 @@ def _coerce_numeric_value_for_string_property(value: ValueT, property: Property,return cast(ValueT, _stringify(value))+def _parse_numeric_bound(value: ValueT) -> int | float | None:+ """Read an ordered-comparison bound as a number, or None when it is not one.++ The filter UI submits a typed-in bound as text ('200'), so numeric text counts as+ numeric here. NaN parses without error but orders meaninglessly, so it is rejected."""+ if _is_numeric_filter_value(value):+ return cast(int | float, value)+ if isinstance(value, str):+ try:+ parsed = float(value)+ except ValueError:+ return None+ return None if math.isnan(parsed) else parsed+ return None+++def _coerce_ordered_bound(+ expr: ast.Expr, value: ValueT, property: Property, team: Team+) -> tuple[ast.Expr, ValueT | int | float]:+ """Coerce an ordered comparison (lt/gt/lte/gte) of a numeric bound against a String LHS.++ Stringifying the value, the way exact/is_not do, would order lexicographically+ ('9' > '10'), so the cast has to go on the LHS instead. HogQL's toFloat prints as+ accurateCastOrNull(..., 'Float64'), so a row whose value does not parse as a number+ becomes NULL and drops out of the comparison, same as a row missing the property.+ The bound comes back in parsed form, or a numeric-text bound would compare as+ String against the Float64 LHS."""+ bound = _parse_numeric_bound(value)+ if bound is None:+ return expr, value++ if not _property_lhs_stays_string(property, team):+ return expr, value++ return ast.Call(name="toFloat", args=[expr]), bound++def _resolve_date_value(value: ValueT, team: Team) -> ValueT:"""Resolve a date value for IS_DATE_* operators.@@ -595,6 +639,29 @@ def _validate_between_values(value: ValueT, operator: PropertyOperator) -> TypeGreturn True+@frozen+class _BetweenComparison:+ left: ast.Expr+ low: int | float | str+ high: int | float | str+++def _coerce_between_bounds(expr: ast.Expr, value: list, property: Property, team: Team) -> _BetweenComparison:+ """Coerce a between/not_between comparison against a String LHS to numeric.++ _validate_between_values already guaranteed both bounds parse as numbers, so a String+ LHS always gets the toFloat cast (see _coerce_ordered_bound for the semantics). The+ bounds are parsed with it, or a numeric-text bound ('10') would compare as String+ against the Float64 LHS."""+ if not _property_lhs_stays_string(property, team):+ return _BetweenComparison(left=expr, low=value[0], high=value[1])++ def _parse(v: object) -> int | float:+ return float(v) if isinstance(v, str) else cast(int | float, v)++ return _BetweenComparison(left=ast.Call(name="toFloat", args=[expr]), low=_parse(value[0]), high=_parse(value[1]))++def _multi_search_found(search_call: ast.Call) -> ast.CompareOperation:"""Create comparison operation to check if multiSearchAnyCaseInsensitive found a match."""return ast.CompareOperation(op=ast.CompareOperationOp.Gt, left=search_call, right=ast.Constant(value=0))@@ -805,7 +872,8 @@ def _expr_to_compare_op(),)elif operator == PropertyOperator.LT:- return ast.CompareOperation(op=ast.CompareOperationOp.Lt, left=expr, right=ast.Constant(value=value))+ left, bound = _coerce_ordered_bound(expr, value, property, team)+ return ast.CompareOperation(op=ast.CompareOperationOp.Lt, left=left, right=ast.Constant(value=bound))elif operator == PropertyOperator.IS_DATE_BEFORE:assert isinstance(value, str)return ast.CompareOperation(@@ -814,7 +882,8 @@ def _expr_to_compare_op(right=_force_datetime(ast.Constant(value=_resolve_date_value(value, team))),)elif operator == PropertyOperator.GT:- return ast.CompareOperation(op=ast.CompareOperationOp.Gt, left=expr, right=ast.Constant(value=value))+ left, bound = _coerce_ordered_bound(expr, value, property, team)+ return ast.CompareOperation(op=ast.CompareOperationOp.Gt, left=left, right=ast.Constant(value=bound))elif operator == PropertyOperator.IS_DATE_AFTER:assert isinstance(value, str)return ast.CompareOperation(@@ -823,28 +892,41 @@ def _expr_to_compare_op(right=_force_datetime(ast.Constant(value=_resolve_date_value(value, team))),)elif operator == PropertyOperator.LTE or operator == PropertyOperator.MAX:- return ast.CompareOperation(op=ast.CompareOperationOp.LtEq, left=expr, right=ast.Constant(value=value))+ left, bound = _coerce_ordered_bound(expr, value, property, team)+ return ast.CompareOperation(op=ast.CompareOperationOp.LtEq, left=left, right=ast.Constant(value=bound))elif operator == PropertyOperator.GTE or operator == PropertyOperator.MIN:- return ast.CompareOperation(op=ast.CompareOperationOp.GtEq, left=expr, right=ast.Constant(value=value))+ left, bound = _coerce_ordered_bound(expr, value, property, team)+ return ast.CompareOperation(op=ast.CompareOperationOp.GtEq, left=left, right=ast.Constant(value=bound))elif operator == PropertyOperator.BETWEEN:_validate_between_values(value, operator)assert isinstance(value, list)+ between = _coerce_between_bounds(expr, value, property, team)return ast.And(exprs=[- ast.CompareOperation(op=ast.CompareOperationOp.GtEq, left=expr, right=ast.Constant(value=value[0])),- ast.CompareOperation(op=ast.CompareOperationOp.LtEq, left=expr, right=ast.Constant(value=value[1])),+ ast.CompareOperation(+ op=ast.CompareOperationOp.GtEq, left=between.left, right=ast.Constant(value=between.low)+ ),+ ast.CompareOperation(+ op=ast.CompareOperationOp.LtEq, left=between.left, right=ast.Constant(value=between.high)+ ),])elif operator == PropertyOperator.NOT_BETWEEN:_validate_between_values(value, operator)assert isinstance(value, list)+ between = _coerce_between_bounds(expr, value, property, team)return ast.Or(exprs=[- ast.CompareOperation(op=ast.CompareOperationOp.Lt, left=expr, right=ast.Constant(value=value[0])),- ast.CompareOperation(op=ast.CompareOperationOp.Gt, left=expr, right=ast.Constant(value=value[1])),+ ast.CompareOperation(+ op=ast.CompareOperationOp.Lt, left=between.left, right=ast.Constant(value=between.low)+ ),+ ast.CompareOperation(+ op=ast.CompareOperationOp.Gt, left=between.left, right=ast.Constant(value=between.high)+ ),# A missing property makes both comparisons NULL and drops the row; keep it, matching- # every other negative operator.- ast.Call(name="isNull", args=[expr]),+ # every other negative operator. With a coerced LHS this also keeps rows whose value+ # does not parse as a number: they match no range, so "not between" holds for them.+ ast.Call(name="isNull", args=[between.left]),])elif operator == PropertyOperator.IS_CLEANED_PATH_EXACT:diff --git a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambrindex aa1c1357f100..f3cad48345ef 100644--- a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr+++ b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr@@ -27,7 +27,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), ifNull(less(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'test_prop'), ''), 'null'), '^"|"$', ''), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'test_prop'), ''), 'null'), '^"|"$', ''), 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -35,7 +35,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), ifNull(greater(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'test_prop'), ''), 'null'), '^"|"$', ''), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'test_prop'), ''), 'null'), '^"|"$', ''), 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -115,7 +115,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))+ WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, 'mango'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))LIMIT 50000'''# ---@@ -131,7 +131,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))+ WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, 'mango'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))LIMIT 50000'''# ---@@ -139,7 +139,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(greater(events.mat_test_prop, '5'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))+ WHERE and(equals(events.team_id, 99999), and(greater(events.mat_test_prop, 'mango'), notEquals(events.mat_test_prop, ''), notEquals(events.mat_test_prop, 'null')))LIMIT 50000'''# ---@@ -219,7 +219,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -227,7 +227,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(greater(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -267,7 +267,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, 'mango'), isNotNull(events.mat_test_prop)))LIMIT 50000'''# ---@@ -275,7 +275,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(greater(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(greater(events.mat_test_prop, 'mango'), isNotNull(events.mat_test_prop)))LIMIT 50000'''# ---@@ -283,7 +283,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(lessOrEquals(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(lessOrEquals(events.mat_test_prop, 'mango'), isNotNull(events.mat_test_prop)))LIMIT 50000'''# ---@@ -291,7 +291,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.mat_test_prop, 'mango'), isNotNull(events.mat_test_prop)))LIMIT 50000'''# ---@@ -319,27 +319,35 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_0_int+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_datetime_constant_against_string_column_errors'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, 5), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), isNotNull(events.mat_test_prop)))LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_1_float+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_0_int'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, 5.5), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5), 0))LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_2_datetime+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_1_float'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5.5), 0))+ LIMIT 50000+ '''+# ---+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_2_numeric_text+ '''+ SELECT count() AS `count()`+ FROM events+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -371,15 +379,7 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_numeric_looking- '''- SELECT count() AS `count()`- FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))- LIMIT 50000- '''-# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_2_string_date_looking+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_date_looking'''SELECT count() AS `count()`FROM events@@ -387,7 +387,7 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_3_string_iso_datetime_looking+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_2_string_iso_datetime_looking'''SELECT count() AS `count()`FROM events@@ -423,7 +423,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_test_prop, '5'), isNotNull(events.mat_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -471,7 +471,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(has(events.properties_group_custom, 'test_prop'), events.properties_group_custom['test_prop'], NULL), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(if(has(events.properties_group_custom, 'test_prop'), events.properties_group_custom['test_prop'], NULL), 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -527,7 +527,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_pp_test_prop, '5'), isNotNull(events.mat_pp_test_prop)))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.mat_pp_test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -543,7 +543,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(less(events.mat_pp_test_prop, '5'), isNotNull(events.mat_pp_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(less(events.mat_pp_test_prop, 'mango'), isNotNull(events.mat_pp_test_prop)))LIMIT 50000'''# ---@@ -551,7 +551,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), and(greater(events.mat_pp_test_prop, '5'), isNotNull(events.mat_pp_test_prop)))+ WHERE and(equals(events.team_id, 99999), and(greater(events.mat_pp_test_prop, 'mango'), isNotNull(events.mat_pp_test_prop)))LIMIT 50000'''# ---@@ -615,7 +615,7 @@'''SELECT count() AS `count()`FROM events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(has(events.person_properties_map_custom, 'test_prop'), events.person_properties_map_custom['test_prop'], NULL), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(if(has(events.person_properties_map_custom, 'test_prop'), events.person_properties_map_custom['test_prop'], NULL), 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -664,10 +664,10 @@WHERE and(equals(person.team_id, 99999), in(id,(SELECT where_optimization.id AS idFROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), and(less(where_optimization.pmat_test_prop, '5'), isNotNull(where_optimization.pmat_test_prop))))))+ WHERE and(equals(where_optimization.team_id, 99999), ifNull(less(accurateCastOrNull(where_optimization.pmat_test_prop, 'Float64'), 5.0), 0)))))GROUP BY person.idHAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))) AS persons- WHERE ifNull(less(persons.properties___test_prop, '5'), 0)+ WHERE ifNull(less(accurateCastOrNull(persons.properties___test_prop, 'Float64'), 5.0), 0)LIMIT 50000'''# ---@@ -698,10 +698,10 @@WHERE and(equals(person.team_id, 99999), in(id,(SELECT where_optimization.id AS idFROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), and(less(where_optimization.pmat_test_prop, '5'), isNotNull(where_optimization.pmat_test_prop))))))+ WHERE and(equals(where_optimization.team_id, 99999), and(less(where_optimization.pmat_test_prop, 'mango'), isNotNull(where_optimization.pmat_test_prop))))))GROUP BY person.idHAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))) AS persons- WHERE ifNull(less(persons.properties___test_prop, '5'), 0)+ WHERE ifNull(less(persons.properties___test_prop, 'mango'), 0)LIMIT 50000'''# ---@@ -715,10 +715,10 @@WHERE and(equals(person.team_id, 99999), in(id,(SELECT where_optimization.id AS idFROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), and(greater(where_optimization.pmat_test_prop, '5'), isNotNull(where_optimization.pmat_test_prop))))))+ WHERE and(equals(where_optimization.team_id, 99999), and(greater(where_optimization.pmat_test_prop, 'mango'), isNotNull(where_optimization.pmat_test_prop))))))GROUP BY person.idHAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))) AS persons- WHERE ifNull(greater(persons.properties___test_prop, '5'), 0)+ WHERE ifNull(greater(persons.properties___test_prop, 'mango'), 0)LIMIT 50000'''# ---diff --git a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.new_events_schema.ambr b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.new_events_schema.ambrindex 8b81c6271c1a..2c4fcec76c27 100644--- a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.new_events_schema.ambr+++ b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.new_events_schema.ambr@@ -27,7 +27,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -35,7 +35,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -115,7 +115,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -131,7 +131,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -139,7 +139,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -219,7 +219,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -227,7 +227,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -267,7 +267,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -275,7 +275,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -283,7 +283,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(lessOrEquals(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(lessOrEquals(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -291,7 +291,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greaterOrEquals(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greaterOrEquals(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -319,27 +319,35 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_0_int[new_events_schema]+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_datetime_constant_against_string_column_errors[new_events_schema]'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 5), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), 0))LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_1_float[new_events_schema]+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_0_int[new_events_schema]'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), 5.5), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5), 0))LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_2_datetime[new_events_schema]+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_1_float[new_events_schema]'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.5), 0))+ LIMIT 50000+ '''+# ---+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces_2_numeric_text[new_events_schema]+ '''+ SELECT count() AS `count()`+ FROM events_json AS events+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -372,11 +380,11 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_numeric_looking[new_events_schema]+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_date_looking[new_events_schema]'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '2024-01-15'), 0))LIMIT 50000'''# ---@@ -388,6 +396,14 @@LIMIT 50000'''# ---+# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_2_string_iso_datetime_looking[new_events_schema]+ '''+ SELECT count() AS `count()`+ FROM events_json AS events+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '2024-01-15T10:30:00Z'), 0))+ LIMIT 50000+ '''+# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_3_string_iso_datetime_looking[new_events_schema]'''SELECT count() AS `count()`@@ -424,7 +440,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -472,7 +488,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.properties.^test_prop)), if(isNull(nullIf(toString(events.properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.test_prop), '[]'), '{}'), toString(events.properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -528,7 +544,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.person_properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---@@ -544,7 +560,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -552,7 +568,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), 'mango'), 0))LIMIT 50000'''# ---@@ -616,7 +632,7 @@'''SELECT count() AS `count()`FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), '{}'), JSONStripEmptyStringsAndNulls(toJSONString(events.person_properties.^test_prop)), if(isNull(nullIf(toString(events.person_properties.test_prop), '')), NULL, if(and(in(ascii(toString(events.person_properties.test_prop)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.test_prop)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.test_prop), '[]'), '{}'), toString(events.person_properties.test_prop)))), '5'), 0))+ WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(events.person_properties.test_prop, 'Float64'), 5.0), 0))LIMIT 50000'''# ---diff --git a/posthog/hogql/test/test_property.py b/posthog/hogql/test/test_property.pyindex aadaf283757d..b7545688b68c 100644--- a/posthog/hogql/test/test_property.py+++ b/posthog/hogql/test/test_property.py@@ -184,7 +184,7 @@ class TestProperty(BaseTest):self._property_to_expr(Property(type="group", group_type_index=0, key="arr", operator="gt", value=100), scope="group"),- self._parse_expr("properties.arr > 100"),+ self._parse_expr("toFloat(properties.arr) > 100"),)@parameterized.expand(@@ -273,19 +273,19 @@ class TestProperty(BaseTest):)self.assertEqual(self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "gt"}),- self._parse_expr("properties.a > '3'"),+ self._parse_expr("toFloat(properties.a) > 3.0"),)self.assertEqual(self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "lt"}),- self._parse_expr("properties.a < '3'"),+ self._parse_expr("toFloat(properties.a) < 3.0"),)self.assertEqual(self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "gte"}),- self._parse_expr("properties.a >= '3'"),+ self._parse_expr("toFloat(properties.a) >= 3.0"),)self.assertEqual(self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "lte"}),- self._parse_expr("properties.a <= '3'"),+ self._parse_expr("toFloat(properties.a) <= 3.0"),)self.assertEqual(self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "icontains"}),@@ -462,16 +462,6 @@ class TestProperty(BaseTest):),)- def test_property_to_expr_generic_lt_gt_unchanged(self):- self.assertEqual(- self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "lt"}),- self._parse_expr("properties.a < '3'"),- )- self.assertEqual(- self._property_to_expr({"type": "event", "key": "a", "value": "3", "operator": "gt"}),- self._parse_expr("properties.a > '3'"),- )-@parameterized.expand([("is_date_before_relative", "-10m", "is_date_before", ast.CompareOperationOp.Lt, "2025-06-09 12:00:00"),@@ -1449,6 +1439,67 @@ class TestProperty(BaseTest):self._property_to_expr({"type": "event", "key": "count", "value": [5, 6], "operator": "exact"}),self._parse_expr("properties.count in (5, 6)"),)+ # ordered operators leave a Numeric-typed LHS alone too, with no toFloat wrap+ self.assertEqual(+ self._property_to_expr({"type": "event", "key": "count", "value": 5, "operator": "gt"}),+ self._parse_expr("properties.count > 5"),+ )++ @parameterized.expand(+ [+ ("person", "person", None),+ ("event", "event", None),+ ("group", "group", 0),+ ]+ )+ def test_property_to_expr_ordered_numeric_filter_on_string_property(self, _name, property_type, group_type_index):+ # An ordered numeric filter on a string-typed (or as-yet-undefined) property compiles to+ # <String> > <number>, which ClickHouse rejects at read time with NO_COMMON_TYPE (386), so+ # the LHS needs a toFloat (accurateCastOrNull) cast that drops non-numeric values instead.+ base: dict = {"type": property_type, "key": "prop", "value": 200, "operator": "gt"}+ if group_type_index is not None:+ base["group_type_index"] = group_type_index+ prefix = {"person": "person.properties", "event": "properties", "group": "group_0.properties"}[property_type]++ for operator, symbol in [("gt", ">"), ("lt", "<"), ("gte", ">="), ("lte", "<=")]:+ self.assertEqual(+ self._property_to_expr({**base, "operator": operator}),+ self._parse_expr(f"toFloat({prefix}.prop) {symbol} 200"),+ )+ self.assertEqual(+ self._property_to_expr({**base, "operator": "between", "value": [5, 10]}),+ self._parse_expr(f"toFloat({prefix}.prop) >= 5 and toFloat({prefix}.prop) <= 10"),+ )+ self.assertEqual(+ self._property_to_expr({**base, "operator": "not_between", "value": [5, 10]}),+ self._parse_expr(+ f"toFloat({prefix}.prop) < 5 or toFloat({prefix}.prop) > 10 or isNull(toFloat({prefix}.prop))"+ ),+ )+ # a non-numeric string value keeps the uncoerced String comparison+ self.assertEqual(+ self._property_to_expr({**base, "value": "abc"}),+ self._parse_expr(f"{prefix}.prop > 'abc'"),+ )++ def test_property_to_expr_numeric_text_bound_parses_against_coerced_lhs(self):+ # The filter UI submits a typed-in bound as text, so "200" must coerce like 200 does.+ # Left uncoerced it compares lexicographically: "9" > "200" matches even though 9 < 200.+ expr = self._property_to_expr({"type": "event", "key": "prop", "value": "200", "operator": "gt"})+ assert isinstance(expr, ast.CompareOperation)+ self.assertEqual(expr.left, ast.Call(name="toFloat", args=[ast.Field(chain=["properties", "prop"])]))+ assert isinstance(expr.right, ast.Constant)+ self.assertIsInstance(expr.right.value, float)+ self.assertEqual(expr.right.value, 200.0)++ # between bounds are validated numeric, so text bounds coerce there too+ expr = self._property_to_expr({"type": "event", "key": "prop", "value": ["5", "10"], "operator": "between"})+ assert isinstance(expr, ast.And)+ upper = expr.exprs[1]+ assert isinstance(upper, ast.CompareOperation)+ assert isinstance(upper.right, ast.Constant)+ self.assertIsInstance(upper.right.value, float)+ self.assertEqual(upper.right.value, 10.0)def test_property_to_expr_event_metadata_invalid_scope(self):with self.assertRaises(Exception) as e:@@ -1709,17 +1760,19 @@ class TestProperty(BaseTest):def test_property_to_expr_between_operator(self):self.assertEqual(self._property_to_expr({"type": "event", "key": "age", "operator": "between", "value": [18, 65]}),- self._parse_expr("(properties.age >= 18 AND properties.age <= 65)"),+ self._parse_expr("(toFloat(properties.age) >= 18 AND toFloat(properties.age) <= 65)"),)self.assertEqual(self._property_to_expr({"type": "person", "key": "age", "operator": "between", "value": [25, 50]}),- self._parse_expr("(person.properties.age >= 25 AND person.properties.age <= 50)"),+ self._parse_expr("(toFloat(person.properties.age) >= 25 AND toFloat(person.properties.age) <= 50)"),)self.assertEqual(self._property_to_expr({"type": "event", "key": "score", "operator": "not_between", "value": [0, 100]}),- self._parse_expr("(properties.score < 0 OR properties.score > 100 OR isNull(properties.score))"),+ self._parse_expr(+ "(toFloat(properties.score) < 0 OR toFloat(properties.score) > 100 OR isNull(toFloat(properties.score)))"+ ),)def test_property_to_expr_between_operator_validation(self):@@ -1782,25 +1835,25 @@ class TestProperty(BaseTest):# Test MIN operator (alias for GTE)self.assertEqual(self._property_to_expr({"type": "event", "key": "age", "operator": "min", "value": 18}),- self._parse_expr("properties.age >= 18"),+ self._parse_expr("toFloat(properties.age) >= 18"),)# Test MAX operator (alias for LTE)self.assertEqual(self._property_to_expr({"type": "event", "key": "age", "operator": "max", "value": 65}),- self._parse_expr("properties.age <= 65"),+ self._parse_expr("toFloat(properties.age) <= 65"),)# Test MIN with person propertiesself.assertEqual(self._property_to_expr({"type": "person", "key": "age", "operator": "min", "value": 25}),- self._parse_expr("person.properties.age >= 25"),+ self._parse_expr("toFloat(person.properties.age) >= 25"),)# Test MAX with person propertiesself.assertEqual(self._property_to_expr({"type": "person", "key": "score", "operator": "max", "value": 100}),- self._parse_expr("person.properties.score <= 100"),+ self._parse_expr("toFloat(person.properties.score) <= 100"),)def test_property_to_expr_semver_operators(self):diff --git a/posthog/hogql/test/test_property_skip_indexes.py b/posthog/hogql/test/test_property_skip_indexes.pyindex 9e8ea3e4bdb6..e96319d70006 100644--- a/posthog/hogql/test/test_property_skip_indexes.py+++ b/posthog/hogql/test/test_property_skip_indexes.py@@ -329,10 +329,11 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):# ``notEquals`` can't be range-pruned by minmax.("neq", PropertyOperator.IS_NOT, "5", False),# Range ops fire minmax via the printer's range-comparison rewrite (``ifNull(less(col, x), 0)`` → ``(less(col, x) AND col IS NOT NULL)``).- ("lt", PropertyOperator.LT, "5", True),- ("gt", PropertyOperator.GT, "5", True),- ("lte", PropertyOperator.LTE, "5", True),- ("gte", PropertyOperator.GTE, "5", True),+ # Non-numeric bounds: a numeric-text bound ("5") now coerces to Float64 and hides the column (see ``..._numeric_constant_against_string_column_coerces``).+ ("lt", PropertyOperator.LT, "mango", True),+ ("gt", PropertyOperator.GT, "mango", True),+ ("lte", PropertyOperator.LTE, "mango", True),+ ("gte", PropertyOperator.GTE, "mango", True),# Multi-value IN uses the printer's ``has([values], col)`` optimized path — minmax prunes granules out of range.("in_multi", PropertyOperator.IN_, ["2", "5"], True),# ILIKE can't use minmax on its own, but the printer's combined form with ``col IS NOT NULL`` does get minmax considered (entirely-NULL granules pruneable).@@ -361,8 +362,9 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):[("eq", PropertyOperator.EXACT, "5", True),# Range ops use minmax via the rewrite — sentinel exclusion is inlined as extra ``notEquals`` clauses so the comparison itself stays bare.- ("lt", PropertyOperator.LT, "5", True),- ("gt", PropertyOperator.GT, "5", True),+ # Non-numeric bounds, same reason as the nullable variant above.+ ("lt", PropertyOperator.LT, "mango", True),+ ("gt", PropertyOperator.GT, "mango", True),# Multi-value IN: ``has([...], col)`` via the printer's optimized path.("in_multi", PropertyOperator.IN_, ["2", "5"], True),# No ``IS NOT NULL`` companion clause here (column is already non-nullable), so minmax has no leverage.@@ -387,9 +389,9 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):@parameterized.expand([- # String constants — lexical compare against the String column; minmax fires for every flavor.+ # Non-numeric string constants — lexical compare against the String column; minmax fires for every flavor.+ # A numeric-looking bound ("5") coerces to Float64 instead; see ``..._numeric_constant_against_string_column_coerces``.("string_pure_alpha", "apple"),- ("string_numeric_looking", "5"),("string_date_looking", "2024-01-15"),("string_iso_datetime_looking", "2024-01-15T10:30:00Z"),]@@ -422,21 +424,38 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):@parameterized.expand([- # Non-string Python constants — printer emits the constant raw (``less(col, 5)`` or ``less(col, toDateTime64('2024-01-15 ...'))``) and ClickHouse refuses ``String < UInt8 / Float64 / DateTime64`` at execution. (Same behavior as the existing equality / IN rewrites — none of them gate on constant type. For numeric/datetime compare, declare ``property_type`` on the PropertyDefinition; see ``test_mat_col_lt_typed_*``.)+ # Numeric constants against an untyped property get a ``toFloat(col)`` wrap, so the+ # comparison executes (no NO_COMMON_TYPE), but the Call hides the column from minmax,+ # same as ``test_mat_col_lt_typed_numeric_property``. Numeric text counts: the filter+ # UI submits a typed-in bound as a string.("int", 5),("float", 5.5),- ("datetime", datetime(2024, 1, 15, 10, 30)),+ ("numeric_text", "5"),])- def test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors(+ def test_mat_col_nullable_minmax_lt_numeric_constant_against_string_column_coerces(self, _name: str, value: Any) -> None:+ self._seed()+ mat_col = self._materialize_with(is_nullable=True, create_minmax_index=True)+ index = get_minmax_index_name(mat_col.name)+ self._assert_indexes(+ self._filter(PropertyOperator.LT, value),+ expected_used=set(),+ expected_not_used={index},+ )++ def test_mat_col_nullable_minmax_lt_datetime_constant_against_string_column_errors(self) -> None:+ # A datetime constant stays raw (``less(col, toDateTime64('2024-01-15 ...'))``) and ClickHouse+ # refuses ``String < DateTime64`` at execution. (Same behavior as the existing equality / IN+ # rewrites — none of them gate on constant type. For datetime compare, declare+ # ``property_type`` on the PropertyDefinition; see ``test_mat_col_lt_typed_datetime_property``.)self._seed()self._materialize_with(is_nullable=True, create_minmax_index=True)- query, values = self._filter_to_sql(self._filter(PropertyOperator.LT, value))+ query, values = self._filter_to_sql(self._filter(PropertyOperator.LT, datetime(2024, 1, 15, 10, 30)))with self.assertRaises(Exception) as ctx:sync_execute(query, values)- # ClickHouse: ``No supertype for types String, UInt8`` or ``No operation less between String and DateTime64``.+ # ClickHouse: ``No operation less between String and DateTime64``.message = str(ctx.exception).lower()assert "supertype" in message or "no operation" in message, (f"Expected a type-mismatch error from ClickHouse, got: {ctx.exception}"@@ -632,8 +651,8 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):("in_multi", PropertyOperator.IN_, ["2", "5"], True),# Sentinel-aware IN path bails when ``''`` / ``'null'`` is in the value set (non-nullable mat cols store both as sentinels), so the bloom filter doesn't fire.("in_with_sentinel", PropertyOperator.IN_, ["5", ""], False),- # Range rewrite emits ``less(col, '5') AND notEquals(col, '') AND notEquals(col, 'null')``; ClickHouse considers each AND-ed clause against every applicable index — minmax fires on ``less``, bloom filter fires on the sentinel ``notEquals`` clauses (granules with no ``''`` / ``'null'`` rows trivially satisfy them).- ("lt", PropertyOperator.LT, "5", True),+ # Range rewrite emits ``less(col, 'mango') AND notEquals(col, '') AND notEquals(col, 'null')``; ClickHouse considers each AND-ed clause against every applicable index — minmax fires on ``less``, bloom filter fires on the sentinel ``notEquals`` clauses (granules with no ``''`` / ``'null'`` rows trivially satisfy them). Non-numeric bound: numeric text coerces and skips the rewrite.+ ("lt", PropertyOperator.LT, "mango", True),])def test_mat_col_non_nullable_bloom_filter(@@ -770,7 +789,8 @@ class TestEventPropertySkipIndexes(_PropertySkipIndexTestBase):stats = HogQLTypeObservability(dialect="clickhouse", source="unknown")with patch("posthog.hogql.printer.utils.create_hogql_type_observability", return_value=stats):- self._filter_to_sql(self._filter(PropertyOperator.LT, "5"))+ # Non-numeric bound: a numeric-text bound coerces to Float64 and skips the range rewrite.+ self._filter_to_sql(self._filter(PropertyOperator.LT, "mango"))if settings.CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA:assert stats.materialized_range_rewrite["fired_compare"] == 0@@ -815,9 +835,10 @@ class TestPersonOnEventsPropertySkipIndexes(_PropertySkipIndexTestBase):@parameterized.expand([("eq", PropertyOperator.EXACT, "5", True),- # Range ops use minmax via the printer's range-comparison rewrite.- ("lt", PropertyOperator.LT, "5", True),- ("gt", PropertyOperator.GT, "5", True),+ # Range ops use minmax via the printer's range-comparison rewrite. Non-numeric+ # bounds: numeric text coerces to Float64 and hides the column.+ ("lt", PropertyOperator.LT, "mango", True),+ ("gt", PropertyOperator.GT, "mango", True),("in_multi", PropertyOperator.IN_, ["2", "5"], True),("icontains_with_isnotnull", PropertyOperator.ICONTAINS, "5", True),# is_set omitted — minmax usage for ``col IS NOT NULL`` is ClickHouse-version-dependent (CH 26.3 yes, 25.12 no).@@ -919,9 +940,10 @@ class TestPersonPropertySkipIndexes(_PropertySkipIndexTestBase):@parameterized.expand([("eq", PropertyOperator.EXACT, "5", True),- # Range ops use minmax via the printer's range-comparison rewrite.- ("lt", PropertyOperator.LT, "5", True),- ("gt", PropertyOperator.GT, "5", True),+ # Range ops use minmax via the printer's range-comparison rewrite. Non-numeric+ # bounds: numeric text coerces to Float64 and hides the column.+ ("lt", PropertyOperator.LT, "mango", True),+ ("gt", PropertyOperator.GT, "mango", True),("icontains_with_isnotnull", PropertyOperator.ICONTAINS, "5", True),# is_set omitted — minmax usage for ``col IS NOT NULL`` is ClickHouse-version-dependent (CH 26.3 yes, 25.12 no).]diff --git a/posthog/management/commands/survey_cohort_bytecode_stl.py b/posthog/management/commands/survey_cohort_bytecode_stl.pyindex 2c184c6f6c7e..dc8980c7dd73 100644--- a/posthog/management/commands/survey_cohort_bytecode_stl.py+++ b/posthog/management/commands/survey_cohort_bytecode_stl.py@@ -102,6 +102,8 @@ RUST_NATIVE_STL: frozenset[str] = frozenset("toDate","multiSearchAnyCaseInsensitive","randomFloat",+ # Ordered numeric property filters compile to a toFloat(...) LHS cast; stl.rs registers it.+ "toFloat",})# inCohort/notInCohort exist in stl.rs but take 2 args (cohort_id, cohort_ids); stored realtime cohortdiff --git a/products/batch_exports/backend/tests/temporal/test_filters.py b/products/batch_exports/backend/tests/temporal/test_filters.pyindex d3fb7d454120..4ae05a3ea94c 100644--- a/products/batch_exports/backend/tests/temporal/test_filters.py+++ b/products/batch_exports/backend/tests/temporal/test_filters.py@@ -75,8 +75,13 @@ pytestmark = [pytest.mark.asyncio, pytest.mark.django_db][{"key": "$created_at", "type": "person", "operator": "between", "value": [0, 1]},],- """and(ifNull(greaterOrEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, %(hogql_val_0)s), \'\'), \'null\'), \'^"|"$\', \'\'), 0.0), 0), ifNull(lessOrEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, %(hogql_val_1)s), \'\'), \'null\'), \'^"|"$\', \'\'), 1.0), 0))""",- {"hogql_val_0": "$created_at", "hogql_val_1": "$created_at"},+ """and(ifNull(greaterOrEquals(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, %(hogql_val_0)s), \'\'), \'null\'), \'^"|"$\', \'\'), %(hogql_val_1)s), 0.0), 0), ifNull(lessOrEquals(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, %(hogql_val_2)s), \'\'), \'null\'), \'^"|"$\', \'\'), %(hogql_val_3)s), 1.0), 0))""",+ {+ "hogql_val_0": "$created_at",+ "hogql_val_1": "Float64",+ "hogql_val_2": "$created_at",+ "hogql_val_3": "Float64",+ },),# HogQL(diff --git a/products/error_tracking/backend/hogvm_stl.py b/products/error_tracking/backend/hogvm_stl.pyindex 0b009481aa32..e4b82c2d403b 100644--- a/products/error_tracking/backend/hogvm_stl.py+++ b/products/error_tracking/backend/hogvm_stl.py@@ -3,6 +3,7 @@ RUST_HOGVM_STL = ["typeof","isNull","values",+ "tuple","length","arrayPushBack","arrayPushFront",@@ -16,16 +17,119 @@ RUST_HOGVM_STL = ["indexOf","notEmpty","match",+ "like",+ "ilike",+ "notLike",+ "notILike","extractRegex","JSONExtract","toDateTime","toDate","multiSearchAnyCaseInsensitive","randomFloat",- "arrayCount",- "arrayMap",+ "concat",+ "lower",+ "upper",+ "reverse",+ "trim",+ "trimLeft",+ "trimRight",+ "isNotNull",+ "jsonParse",+ "jsonStringify",+ "isValidJSON",+ "toInt",+ "toFloat",+ "ifNull",+ "coalesce",+ "assumeNotNull",+ "empty",+ "keys",+ "round",+ "floor",+ "min2",+ "max2",+ "range",+ "substring",+ "replaceOne",+ "replaceAll",+ "splitByString",+ "startsWith",+ "position",+ "positionCaseInsensitive",+ "JSONHas",+ "JSONLength",+ "JSONExtractString",+ "JSONExtractInt",+ "JSONExtractFloat",+ "JSONExtractBool",+ "JSONExtractArrayRaw",+ "fromUnixTimestamp",+ "fromUnixTimestampMilli",+ "toUnixTimestamp",+ "toUnixTimestampMilli",+ "toTimeZone",+ "toYear",+ "toMonth",+ "toYYYYMM",+ "dateTrunc",+ "toStartOfDay",+ "toStartOfHour",+ "toStartOfMonth",+ "toStartOfWeek",+ "toIntervalDay",+ "toIntervalHour",+ "toIntervalMinute",+ "toIntervalMonth",+ "dateAdd",+ "addDays",+ "dateDiff",+ "formatDateTime",+ "isIPAddressInRange",+ "md5Hex",+ "md5",+ "sha256Hex",+ "sha256",+ "sha1Hex",+ "sha1",+ "sha256HmacChainHex",+ "sha256HmacChain",+ "sha1HmacChainHex",+ "sha1HmacChain",+ "base64Encode",+ "base64Decode",+ "tryBase64Decode",+ "encodeURLComponent",+ "decodeURLComponent",+ "tryDecodeURLComponent",+ "toUUID",+ "generateUUIDv4",+ "now",+ "today",+ "HogError",+ "Error",+ "RetryError",+ "NotImplementedError",+ "equals",+ "notEquals",+ "greater",+ "greaterOrEquals",+ "less",+ "lessOrEquals",+ "plus",+ "minus",+ "and",+ "or",+ "not",+ "if",+ "multiIf",+ "in",+ "inCohort",+ "notInCohort","arrayFilter",- "sortableSemver",+ "arrayMap","arrayExists",+ "arrayCount","arrayReduce",+ "sortableSemver",]diff --git a/products/error_tracking/backend/tests/api/test_assignment_rules.py b/products/error_tracking/backend/tests/api/test_assignment_rules.pyindex 7938624c9ee7..bf17f89863c0 100644--- a/products/error_tracking/backend/tests/api/test_assignment_rules.py+++ b/products/error_tracking/backend/tests/api/test_assignment_rules.py@@ -52,6 +52,27 @@ class TestAssignmentRuleAPI(APIBaseTest):assert rule.bytecode is not Noneassert len(rule.bytecode) > 0+ def test_create_accepts_ordered_numeric_filter_on_undefined_property(self) -> None:+ # The filter compiles to a toFloat(...) cast, and rule validation checks every called+ # global against the Rust VM STL snapshot. A stale snapshot rejected the rule with+ # "Unknown global function: toFloat".+ filters = {+ "type": "AND",+ "values": [+ {+ "type": "AND",+ "values": [{"key": "http_status", "type": "event", "value": "200", "operator": "gt"}],+ }+ ],+ }+ response = self.client.post(+ self._url(),+ data={"filters": filters, "assignee": {"type": "user", "id": self.user.id}},+ format="json",+ )++ assert response.status_code == status.HTTP_201_CREATED+def test_create_accepts_order_key_and_ignores_frontend_only_fields(self) -> None:response = self.client.post(self._url(),