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.

fix(hogql): preserve grouped native property expressions (#125296)

Sandy Spicerfd81ea4b17ed
diff --git a/docs/published/handbook/engineering/databases/hogql-python.md b/docs/published/handbook/engineering/databases/hogql-python.md
index fe603570a644..7c0e5aff8714 100644
--- a/docs/published/handbook/engineering/databases/hogql-python.md
+++ b/docs/published/handbook/engineering/databases/hogql-python.md
@@ -183,6 +183,8 @@ Numeric, Boolean and DateTime property definitions keep their conversions when c
Boolean conversion reads the native path directly because object and array text cannot match `true` or `false`; numeric conversions already read native paths directly.
Constants starting with `[` or `{` keep the full property read because arrays and objects serialize differently from scalars.
Single-property reads serialize sub-objects with ClickHouse's JSON formatter; whole-document reads still remove declared defaults.
+Grouping keys and expressions evaluated after grouping use the general property reader so conversions reference the same expression as GROUP BY.
+This includes window inputs, HAVING, ORDER BY and LIMIT BY; ordinary aggregate inputs and row-level predicates retain direct-path optimizations.
Raw SQL property readers preserve backslashes before forward slashes whether ClickHouse's `output_format_json_escape_forward_slashes` setting is enabled or disabled.
Native queries disable forward-slash escaping so object and array text retains `/`.
diff --git a/posthog/hogql/transforms/clickhouse_property_resolution.py b/posthog/hogql/transforms/clickhouse_property_resolution.py
index 75ba5a849855..b048c321e014 100644
--- a/posthog/hogql/transforms/clickhouse_property_resolution.py
+++ b/posthog/hogql/transforms/clickhouse_property_resolution.py
@@ -39,7 +39,7 @@ from posthog.hogql.context import HogQLContext
from posthog.hogql.database.models import DatabaseField, MapStringDatabaseField, StringJSONDatabaseField
from posthog.hogql.database.schema.util.null_sentinels import MAT_COL_NULL_SENTINELS, null_if_sentinels
from posthog.hogql.errors import QueryError
-from posthog.hogql.functions.mapping import HOGQL_COMPARISON_MAPPING
+from posthog.hogql.functions.mapping import HOGQL_COMPARISON_MAPPING, find_hogql_aggregation
from posthog.hogql.printer.base import resolve_field_type
from posthog.hogql.printer.clickhouse import AI_BLOOM_FILTER_PROPERTIES, COLUMNS_WITH_HACKY_OPTIMIZED_NULL_HANDLING
from posthog.hogql.restricted_properties import (
@@ -1205,10 +1205,32 @@ class ClickHousePropertyResolver(CloningVisitor):
try:
if not node.group_by and node.group_by_mode != "all":
return super().visit_select_query(node)
- result = super().visit_select_query(replace(node, having=None, order_by=None))
+ result = super().visit_select_query(
+ replace(
+ node,
+ select=[],
+ group_by=None,
+ having=None,
+ order_by=None,
+ qualify=None,
+ window_exprs=None,
+ limit_by=None,
+ interpolate=None,
+ )
+ )
self._in_grouped_clause = True
+ result.select = [self.visit(expr) for expr in node.select]
+ result.group_by = [self.visit(expr) for expr in node.group_by] if node.group_by else None
result.having = self.visit(node.having)
result.order_by = [self.visit(expr) for expr in node.order_by] if node.order_by else None
+ result.qualify = self.visit(node.qualify)
+ result.window_exprs = (
+ {name: self.visit(expr) for name, expr in node.window_exprs.items()} if node.window_exprs else None
+ )
+ result.limit_by = self.visit(node.limit_by)
+ result.interpolate = (
+ [self.visit(expr) for expr in node.interpolate] if node.interpolate is not None else None
+ )
return result
finally:
self._in_grouped_clause = was_in_grouped_clause
@@ -1245,9 +1267,6 @@ class ClickHousePropertyResolver(CloningVisitor):
Only a single-key access (`properties.x`, no deeper `.a.b`) maps to one backing column. A multi-key access reads
the column and then JSON-extracts deeper, so it can't use the bare-column comparison rewrites.
"""
- # Bare-column rewrites after aggregation can reference a column absent from GROUP BY.
- if self._in_grouped_clause:
- return None
node = self._lowered_property_operand(expr)
if node is not None and len(node.keys) == 1:
field_type = _blob_field_type_of(node)
@@ -1333,6 +1352,17 @@ class ClickHousePropertyResolver(CloningVisitor):
# --- comparison / call rewrites ---
def visit_call(self, node: ast.Call) -> ast.Expr:
+ if self._in_grouped_clause:
+ if find_hogql_aggregation(node.name):
+ self._in_grouped_clause = False
+ try:
+ return super().visit_call(node)
+ finally:
+ self._in_grouped_clause = True
+ # Shortcuts can introduce raw columns unavailable after grouping. WindowFunction is a separate node,
+ # so its inputs keep the grouped context while ordinary aggregates above read original rows.
+ return super().visit_call(node)
+
if node.name == "indexHint":
self._index_hint_depth += 1
try:
@@ -1894,6 +1924,9 @@ class ClickHousePropertyResolver(CloningVisitor):
return _call("isNotNull", [_json_subcolumn_value_expr(field_type, [first_key], source=source)])
def visit_compare_operation(self, node: ast.CompareOperation) -> ast.Expr:
+ if self._in_grouped_clause:
+ return super().visit_compare_operation(node)
+
# Try each skip-index comparison rewrite in order. Each one consumes the property operand and returns the
# rewritten comparison, so once one matches we must NOT also substitute the value. (session_id is left to the
# printer — it optimizes a real column, not a property.)
diff --git a/posthog/hogql/transforms/test/test_property_types.py b/posthog/hogql/transforms/test/test_property_types.py
index 52af7059d9d7..1a96585cd9a2 100644
--- a/posthog/hogql/transforms/test/test_property_types.py
+++ b/posthog/hogql/transforms/test/test_property_types.py
@@ -20,6 +20,7 @@ from unittest.mock import patch
from django.conf import settings
from django.test import SimpleTestCase, override_settings
+from clickhouse_driver.errors import ServerException
from hypothesis import (
HealthCheck,
example,
@@ -138,6 +139,36 @@ class _NewEventsSchemaArraySubcolumnsHelpers:
@override_settings(CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA=True)
class TestNewEventsSchemaArraySubcolumns(_NewEventsSchemaArraySubcolumnsHelpers, SimpleTestCase):
+ @parameterized.expand(
+ [
+ (f"{conversion}_{windowed}", conversion, windowed)
+ for conversion in ("toFloat", "toInt")
+ for windowed in (False, True)
+ ]
+ )
+ def test_grouped_numeric_conversion_reads_the_group_key(self, _name: str, conversion: str, windowed: bool) -> None:
+ value = f"{conversion}(properties.value)"
+ if windowed:
+ value = f"sum({value}) OVER ()"
+ printed = self._print_select(f"SELECT {value}, count() FROM events GROUP BY properties.value")
+ assert f"accurateCastOrNull({json_dynamic_read_sql('events.properties', ['value'])}," in printed
+
+ def test_grouped_comparisons_preserve_group_key_and_scan_optimizations(self) -> None:
+ printed = self._print_select(
+ "SELECT toString(properties.value) AS value, "
+ "if(toString(properties.value) = 'ready', 1, 0), countIf(properties.value = 'ready') "
+ "FROM events WHERE properties.value = 'ready' GROUP BY value"
+ )
+ assert printed.count(f"toString({json_dynamic_read_sql('events.properties', ['value'])})") == 2
+ assert printed.count("CAST(events.properties.value, 'Nullable(String)')") == 2
+
+ def test_nested_aggregate_keeps_direct_numeric_reads(self) -> None:
+ printed = self._print_select(
+ "SELECT properties.value, sum(sum(toFloat(properties.value))) OVER () "
+ "FROM events WHERE toFloat(properties.value) > 0 GROUP BY properties.value"
+ )
+ assert printed.count("accurateCastOrNull(events.properties.value,") == 2
+
@parameterized.expand(
[
("dynamic", "properties.value = '5'", "CAST(events.properties.value, 'Nullable(String)')"),
@@ -467,6 +498,177 @@ class TestNewEventsSchemaArraySubcolumns(_NewEventsSchemaArraySubcolumnsHelpers,
@override_settings(CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA=True)
@pytest.mark.usefixtures("clickhouse_database")
class TestNewEventsSchemaArraySubcolumnsClickhouse(_NewEventsSchemaArraySubcolumnsHelpers, SimpleTestCase):
+ @parameterized.expand(
+ [
+ (
+ "comparison",
+ "SELECT toString(properties.value) AS value, "
+ "if(toString(properties.value) = 'ready', 1, 0), count() "
+ "FROM events GROUP BY value ORDER BY value",
+ ['{"value":"done"}', '{"value":"ready"}', '{"value":"ready"}'],
+ [("done", 0, 1), ("ready", 1, 2)],
+ ),
+ (
+ "numeric",
+ "SELECT toFloat(properties.value) AS value, count() "
+ "FROM events GROUP BY properties.value ORDER BY value",
+ ['{"value":"2"}', '{"value":"7"}', '{"value":"7"}'],
+ [(2.0, 1), (7.0, 2)],
+ ),
+ ]
+ + [
+ (name, query, ['{"value":"2"}', '{"value":"07"}', '{"value":"7"}', '{"value":"7"}'], expected)
+ for name, query, expected in [
+ (
+ "alias",
+ "SELECT properties.value AS original, toFloat(original), count() "
+ "FROM events GROUP BY original ORDER BY original",
+ [("07", 7.0, 1), ("2", 2.0, 1), ("7", 7.0, 2)],
+ ),
+ (
+ "having_order",
+ "SELECT properties.value AS original, count() FROM events GROUP BY properties.value "
+ "HAVING toFloat(properties.value) > 2 ORDER BY toInt(properties.value), original",
+ [("07", 1), ("7", 2)],
+ ),
+ (
+ "window",
+ "SELECT properties.value AS original, sum(toFloat(properties.value)) OVER () "
+ "FROM events GROUP BY properties.value ORDER BY original",
+ [("07", 16.0), ("2", 16.0), ("7", 16.0)],
+ ),
+ (
+ "nested_aggregate",
+ "SELECT properties.value AS original, sum(sum(toFloat(properties.value))) OVER () "
+ "FROM events GROUP BY properties.value ORDER BY original",
+ [("07", 23.0), ("2", 23.0), ("7", 23.0)],
+ ),
+ (
+ "named_window_limit_by",
+ "SELECT properties.value AS original, sum(toFloat(properties.value)) OVER w AS total "
+ "FROM events GROUP BY properties.value "
+ "WINDOW w AS (PARTITION BY toInt(properties.value) ORDER BY toInt(properties.value) "
+ "ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) "
+ "ORDER BY original LIMIT 1 BY toInt(properties.value)",
+ [("07", 14.0), ("2", 2.0)],
+ ),
+ (
+ "explicit_conversion",
+ "SELECT toFloat(properties.value) AS numeric, count() "
+ "FROM events GROUP BY toFloat(properties.value) ORDER BY numeric",
+ [(2.0, 1), (7.0, 3)],
+ ),
+ (
+ "group_by_all",
+ "SELECT toFloat(properties.value) AS numeric, count() FROM events GROUP BY ALL ORDER BY numeric",
+ [(2.0, 1), (7.0, 3)],
+ ),
+ (
+ "subquery_cte",
+ "WITH grouped AS (SELECT properties.value AS original, sum(toFloat(properties.value)) AS total "
+ "FROM events GROUP BY properties.value) "
+ "SELECT toFloat(original), sum(total) FROM grouped GROUP BY original ORDER BY original",
+ [(7.0, 7.0), (2.0, 2.0), (7.0, 14.0)],
+ ),
+ (
+ "group_by_all_mixed_aggregate",
+ "SELECT toFloat(properties.value) + sum(toFloat(properties.value)) AS total, count() "
+ "FROM events GROUP BY ALL ORDER BY total",
+ [(4.0, 1), (28.0, 3)],
+ ),
+ (
+ "nested_select",
+ "SELECT properties.value AS original, (SELECT sum(toFloat(properties.value)) FROM events), "
+ "toFloat(properties.value) FROM events GROUP BY properties.value ORDER BY original",
+ [("07", 23.0, 7.0), ("2", 23.0, 2.0), ("7", 23.0, 7.0)],
+ ),
+ (
+ "ungrouped_property",
+ "SELECT properties.value FROM events GROUP BY toFloat(properties.value)",
+ None,
+ ),
+ (
+ "ungrouped_window",
+ "SELECT count(), sum(toFloat(properties.value)) OVER () FROM events GROUP BY ALL",
+ None,
+ ),
+ ]
+ ]
+ + [
+ (
+ mode,
+ f"SELECT properties.value AS original, toFloat(properties.value), count() FROM events "
+ f"GROUP BY {grouping} ORDER BY original",
+ ['{"value":"2"}', '{"value":"7"}', '{"value":"7"}'],
+ [("2", 2.0, 1), ("7", 7.0, 2), (None, None, 3)],
+ )
+ for mode, grouping in [
+ ("rollup", "ROLLUP(properties.value)"),
+ ("cube", "CUBE(properties.value)"),
+ ("grouping_sets", "GROUPING SETS ((properties.value), ())"),
+ ]
+ ]
+ + [
+ (
+ "numeric_metadata",
+ "SELECT properties.value AS numeric, count() FROM events GROUP BY properties.value ORDER BY numeric",
+ ['{"value":"2"}', '{"value":"07"}', '{"value":"7"}', '{"value":"7"}'],
+ [(2.0, 1), (7.0, 3)],
+ "Numeric",
+ ),
+ (
+ "null_and_invalid",
+ "SELECT properties.value AS original, toFloat(properties.value), count() "
+ "FROM events GROUP BY properties.value ORDER BY original",
+ ["{}", '{"value":null}', '{"value":""}', '{"value":"invalid"}', '{"value":"7"}'],
+ [("", None, 1), ("7", 7.0, 1), ("invalid", None, 1), (None, None, 2)],
+ "String",
+ ("blob", "native"),
+ ),
+ ]
+ )
+ def test_grouped_property_queries(
+ self,
+ _name: str,
+ query: str,
+ documents: list[str],
+ expected: list[tuple[object, ...]] | None,
+ property_type: str = "String",
+ readers: tuple[str, ...] = ("blob", "map", "native"),
+ ) -> None:
+ for reader in readers:
+ with self.subTest(reader=reader):
+ context = self._context(
+ use_new_events_schema=reader == "native", event_properties={"value": {"type": property_type}}
+ )
+ context.modifiers.propertyGroupsMode = (
+ PropertyGroupsMode.OPTIMIZED if reader == "map" else PropertyGroupsMode.DISABLED
+ )
+ context.modifiers.materializationMode = (
+ MaterializationMode.LEGACY_NULL_AS_NULL if reader == "map" else MaterializationMode.DISABLED
+ )
+ with patch("posthog.hogql.printer.utils.build_property_swapper"):
+ printed, _ = prepare_and_print_ast(parse_select(query), context, "clickhouse")
+ if reader == "map":
+ assert "properties_group_custom" in printed
+ source = (
+ "events_json AS (SELECT 1 AS team_id, CAST(document, 'JSON') AS properties "
+ "FROM (SELECT arrayJoin(%(documents)s) AS document)) "
+ if reader == "native"
+ else "events AS (SELECT 1 AS team_id, document AS properties, "
+ "CAST(JSONExtractKeysAndValues(document, 'String'), 'Map(String, String)') AS properties_group_custom "
+ "FROM (SELECT arrayJoin(%(documents)s) AS document)) "
+ )
+ sql = "WITH " + source + printed
+ if printed.startswith("WITH "):
+ sql = "WITH " + source.rstrip() + ", " + printed.removeprefix("WITH ")
+ if expected is None:
+ with pytest.raises(ServerException, match="not under aggregate function and not in GROUP BY"):
+ sync_execute(sql, {**context.values, "documents": documents})
+ else:
+ rows = sync_execute(sql, {**context.values, "documents": documents})
+ assert rows == expected
+
@parameterized.expand([("declared", EVENTS_PROPERTIES_JSON_TYPE()), ("dynamic", "JSON")])
def test_string_paths_read_empty_as_null(self, _name: str, json_type: str) -> None:
context = self._context()
diff --git a/posthog/session_recordings/queries/test/listing_recordings/__snapshots__/test_session_recording_list_operands_queries.new_events_schema.ambr b/posthog/session_recordings/queries/test/listing_recordings/__snapshots__/test_session_recording_list_operands_queries.new_events_schema.ambr
index 5052acac63cb..9c54d2814c5e 100644
--- a/posthog/session_recordings/queries/test/listing_recordings/__snapshots__/test_session_recording_list_operands_queries.new_events_schema.ambr
+++ b/posthog/session_recordings/queries/test/listing_recordings/__snapshots__/test_session_recording_list_operands_queries.new_events_schema.ambr
@@ -266,13 +266,13 @@
FROM events_json AS events
WHERE and(equals(events.team_id, 99999), notEmpty(if(notEquals(toJSONString(events.properties.^`$session_id`), '{}'), toJSONString(events.properties.^`$session_id`), if(isNull(nullIf(toString(events.properties.`$session_id`), '')), NULL, if(and(in(ascii(toString(events.properties.`$session_id`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$session_id`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$session_id`), '[]'), '{}'), toString(events.properties.`$session_id`))))), lessOrEquals(events.timestamp, toDateTime64(now64(6, 'UTC'), 6, 'UTC')), and(equals(events.event, '$pageview'), ifNull(notEquals(CAST(events.properties.vip, 'Nullable(String)'), 'true'), 1)), greaterOrEquals(events.timestamp, toDateTime64('2020-12-28 00:00:00.000000', 6, 'UTC')))
GROUP BY if(notEquals(toJSONString(events.properties.^`$session_id`), '{}'), toJSONString(events.properties.^`$session_id`), if(isNull(nullIf(toString(events.properties.`$session_id`), '')), NULL, if(and(in(ascii(toString(events.properties.`$session_id`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$session_id`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$session_id`), '[]'), '{}'), toString(events.properties.`$session_id`))))
- HAVING and(equals(countIf(ifNull(equals(if(notEquals(toJSONString(events.properties.^vip), '{}'), toJSONString(events.properties.^vip), if(isNull(events.properties.vip), NULL, if(and(in(ascii(toString(events.properties.vip)), tuple(91, 123)), in(ascii(toJSONString(events.properties.vip)), tuple(91, 123))), toJSONString(events.properties.vip), toString(events.properties.vip)))), 'true'), 0)), 0), equals(countIf(ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(events.properties.`$pathname`), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), toJSONString(events.properties.`$pathname`), toString(events.properties.`$pathname`))))), '%target%'), 0)), 0))
+ HAVING and(equals(countIf(ifNull(equals(CAST(events.properties.vip, 'Nullable(String)'), 'true'), 0)), 0), equals(countIf(ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(events.properties.`$pathname`), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), toJSONString(events.properties.`$pathname`), toString(events.properties.`$pathname`))))), '%target%'), 0)), 0))
LIMIT 1000000)), globalIn(s.session_id,
(SELECT if(notEquals(toJSONString(events.properties.^`$session_id`), '{}'), toJSONString(events.properties.^`$session_id`), if(isNull(nullIf(toString(events.properties.`$session_id`), '')), NULL, if(and(in(ascii(toString(events.properties.`$session_id`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$session_id`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$session_id`), '[]'), '{}'), toString(events.properties.`$session_id`)))) AS session_id
FROM events_json AS events
WHERE and(equals(events.team_id, 99999), notEmpty(if(notEquals(toJSONString(events.properties.^`$session_id`), '{}'), toJSONString(events.properties.^`$session_id`), if(isNull(nullIf(toString(events.properties.`$session_id`), '')), NULL, if(and(in(ascii(toString(events.properties.`$session_id`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$session_id`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$session_id`), '[]'), '{}'), toString(events.properties.`$session_id`))))), lessOrEquals(events.timestamp, toDateTime64(now64(6, 'UTC'), 6, 'UTC')), and(equals(events.event, '$pageview'), ifNull(notILike(toString(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(events.properties.`$pathname`), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), toJSONString(events.properties.`$pathname`), toString(events.properties.`$pathname`))))), '%target%'), 1)), greaterOrEquals(events.timestamp, toDateTime64('2020-12-28 00:00:00.000000', 6, 'UTC')))
GROUP BY if(notEquals(toJSONString(events.properties.^`$session_id`), '{}'), toJSONString(events.properties.^`$session_id`), if(isNull(nullIf(toString(events.properties.`$session_id`), '')), NULL, if(and(in(ascii(toString(events.properties.`$session_id`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$session_id`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$session_id`), '[]'), '{}'), toString(events.properties.`$session_id`))))
- HAVING and(equals(countIf(ifNull(equals(if(notEquals(toJSONString(events.properties.^vip), '{}'), toJSONString(events.properties.^vip), if(isNull(events.properties.vip), NULL, if(and(in(ascii(toString(events.properties.vip)), tuple(91, 123)), in(ascii(toJSONString(events.properties.vip)), tuple(91, 123))), toJSONString(events.properties.vip), toString(events.properties.vip)))), 'true'), 0)), 0), equals(countIf(ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(events.properties.`$pathname`), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), toJSONString(events.properties.`$pathname`), toString(events.properties.`$pathname`))))), '%target%'), 0)), 0))
+ HAVING and(equals(countIf(ifNull(equals(CAST(events.properties.vip, 'Nullable(String)'), 'true'), 0)), 0), equals(countIf(ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(events.properties.`$pathname`), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), toJSONString(events.properties.`$pathname`), toString(events.properties.`$pathname`))))), '%target%'), 0)), 0))
LIMIT 1000000))))
GROUP BY s.session_id
HAVING and(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), equals(max(s.is_deleted), 0))
diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr
index 8d1c882ecb97..2468bde7c96f 100644
--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr
+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.new_events_schema.ambr
@@ -19,7 +19,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -87,7 +87,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -150,7 +150,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -326,7 +326,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -384,7 +384,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -442,7 +442,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -500,7 +500,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -558,7 +558,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -671,7 +671,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -734,7 +734,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -792,7 +792,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -851,7 +851,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -914,7 +914,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -978,7 +978,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -1043,7 +1043,7 @@
argMaxMerge(ev.source_state) AS source,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -1106,7 +1106,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -1174,7 +1174,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 1))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -1242,7 +1242,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 4))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
@@ -1310,7 +1310,7 @@
and isNull(i)), ev.occ, toUInt64(0)), range(0, 3))) AS volumeRange,
argMaxMerge(ev.library_state) AS library
FROM
- (SELECT cityHash64(JSONExtractString(ifNull(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, toJSONString(e.properties.`$exception_fingerprint`))), ''))) AS fp_hash,
+ (SELECT cityHash64(JSONExtractString(ifNull(toJSONString(if(notEquals(toJSONString(e.properties.^`$exception_fingerprint`), '{}'), toJSONString(e.properties.^`$exception_fingerprint`), if(isNull(e.properties.`$exception_fingerprint`), NULL, if(and(in(ascii(toString(e.properties.`$exception_fingerprint`)), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_fingerprint`)), tuple(91, 123))), toJSONString(e.properties.`$exception_fingerprint`), toString(e.properties.`$exception_fingerprint`))))), ''))) AS fp_hash,
max(toTimeZone(e.timestamp, 'UTC')) AS last_seen_fp,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_functions`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_functions`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_functions`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_functions`[-1]), '[]'), '{}'), toString(e.properties.`$exception_functions`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS function_state,
argMaxState(if(isNull(nullIf(toString(e.properties.`$exception_sources`[-1]), '')), NULL, if(and(in(ascii(toString(e.properties.`$exception_sources`[-1])), tuple(91, 123)), in(ascii(toJSONString(e.properties.`$exception_sources`[-1])), tuple(91, 123))), nullIf(nullIf(toJSONString(e.properties.`$exception_sources`[-1]), '[]'), '{}'), toString(e.properties.`$exception_sources`[-1]))), toTimeZone(e.timestamp, 'UTC')) AS source_state,
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.new_events_schema.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.new_events_schema.ambr
index 8fe166f2af35..0c064a2ec03d 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.new_events_schema.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.new_events_schema.ambr
@@ -6890,7 +6890,7 @@
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
- divide(minus(0, accurateCastOrNull(events.properties.`$timezone_offset`, 'Float64')), 60) AS breakdown_value,
+ divide(minus(0, accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$timezone_offset`), '{}'), toJSONString(events.properties.^`$timezone_offset`), if(isNull(events.properties.`$timezone_offset`), NULL, if(and(in(ascii(toString(events.properties.`$timezone_offset`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$timezone_offset`)), tuple(91, 123))), toJSONString(events.properties.`$timezone_offset`), toString(events.properties.`$timezone_offset`)))), 'Float64')), 60) AS breakdown_value,
if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), events.properties.`$session_id`, NULL) AS session_id,
any(if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events_json AS events
@@ -6934,7 +6934,7 @@
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
- divide(minus(0, accurateCastOrNull(events.properties.`$timezone_offset`, 'Float64')), 60) AS breakdown_value,
+ divide(minus(0, accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$timezone_offset`), '{}'), toJSONString(events.properties.^`$timezone_offset`), if(isNull(events.properties.`$timezone_offset`), NULL, if(and(in(ascii(toString(events.properties.`$timezone_offset`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$timezone_offset`)), tuple(91, 123))), toJSONString(events.properties.`$timezone_offset`), toString(events.properties.`$timezone_offset`)))), 'Float64')), 60) AS breakdown_value,
if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), events.properties.`$session_id`, NULL) AS session_id,
any(if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events_json AS events
@@ -6978,7 +6978,7 @@
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
- divide(minus(0, accurateCastOrNull(events.properties.`$timezone_offset`, 'Float64')), 60) AS breakdown_value,
+ divide(minus(0, accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$timezone_offset`), '{}'), toJSONString(events.properties.^`$timezone_offset`), if(isNull(events.properties.`$timezone_offset`), NULL, if(and(in(ascii(toString(events.properties.`$timezone_offset`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$timezone_offset`)), tuple(91, 123))), toJSONString(events.properties.`$timezone_offset`), toString(events.properties.`$timezone_offset`)))), 'Float64')), 60) AS breakdown_value,
if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), events.properties.`$session_id`, NULL) AS session_id,
any(if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events_json AS events
@@ -7022,7 +7022,7 @@
FROM
(SELECT any(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS filtered_person_id,
count() AS filtered_pageview_count,
- divide(minus(0, accurateCastOrNull(events.properties.`$timezone_offset`, 'Float64')), 60) AS breakdown_value,
+ divide(minus(0, accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$timezone_offset`), '{}'), toJSONString(events.properties.^`$timezone_offset`), if(isNull(events.properties.`$timezone_offset`), NULL, if(and(in(ascii(toString(events.properties.`$timezone_offset`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$timezone_offset`)), tuple(91, 123))), toJSONString(events.properties.`$timezone_offset`), toString(events.properties.`$timezone_offset`)))), 'Float64')), 60) AS breakdown_value,
if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), events.properties.`$session_id`, NULL) AS session_id,
any(if(ifNull(equals(bitAnd(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 76), 15), 7), 0), fromUnixTimestamp(intDiv(accurateCastOrNull(bitShiftRight(toUInt128(toUUIDOrNull(events.properties.`$session_id`)), 80), 'Int64'), 1000)), NULL)) AS start_timestamp
FROM events_json AS events