: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(oauth): let credential-less CIMD private_key_jwt clients fall back to PKCE (#80746)
Andrew Maguiree0d498282586
diff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.pyindex c6c672409027..b7450dd7efc0 100644--- a/posthog/api/oauth/test_views.py+++ b/posthog/api/oauth/test_views.py@@ -641,6 +641,7 @@ class TestOAuthAPI(APIBaseTest):def _create_private_key_jwt_app_and_grant(self,+ is_cimd_client: bool = True,) -> tuple[OAuthApplication, OAuthGrant, rsa.RSAPrivateKey]:cimd_url = "https://partner.example.com/oauth/client-metadata"private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)@@ -653,8 +654,8 @@ class TestOAuthAPI(APIBaseTest):redirect_uris="https://partner.example.com/callback",user=self.user,algorithm="RS256",- is_cimd_client=True,- cimd_metadata_url=cimd_url,+ is_cimd_client=is_cimd_client,+ cimd_metadata_url=cimd_url if is_cimd_client else None,jwks_uri="https://partner.example.com/.well-known/jwks.json",)grant = OAuthGrant.objects.create(@@ -764,8 +765,107 @@ class TestOAuthAPI(APIBaseTest):self.assertEqual(response.json()["error"], "temporarily_unavailable")@override_settings(SITE_URL="https://us.posthog.com")- def test_private_key_jwt_cimd_client_rejected_without_assertion(self):- # The confidential client must still fail closed when it presents no credential at all.+ def test_credentialless_cimd_private_key_jwt_client_completes_pkce_exchange(self):+ # A CIMD client's private_key_jwt declaration is partner metadata; a partner whose+ # runtime still authenticates with `none` (ChatGPT declares the method but never+ # sends assertions) must be able to complete a PKCE exchange rather than being+ # locked out of every code and refresh grant.+ app, grant, _ = self._create_private_key_jwt_app_and_grant()+ with (+ patch("posthog.api.oauth.views.posthoganalytics.capture") as mock_capture,+ patch("posthog.api.oauth.views.enqueue_cimd_refresh_if_stale") as mock_refresh,+ ):+ response = self.post(+ "/oauth/token/",+ {+ "grant_type": "authorization_code",+ "client_id": app.client_id,+ "redirect_uri": "https://partner.example.com/callback",+ "code_verifier": self.code_verifier,+ "code": grant.code,+ },+ )+ self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)+ self.assertIn("access_token", response.json())+ issued = [c for c in mock_capture.call_args_list if c.kwargs.get("event") == "oauth_token_issued"]+ self.assertEqual(len(issued), 1)+ # The stamp is what tells "partner still on none" apart from "partner switched to+ # assertions" in analytics, which is the signal for retiring the fallback.+ self.assertEqual(issued[0].kwargs["properties"]["client_auth_method"], "none")+ # Fallback exchanges are the only requests a client living on `none` sends, so+ # they must keep the CIMD document fresh the same way the assertion path does.+ mock_refresh.assert_called_once_with(app.cimd_metadata_url)++ @override_settings(SITE_URL="https://us.posthog.com")+ def test_non_cimd_confidential_client_rejected_without_assertion(self):+ # The credential-less fallback is scoped to CIMD registrations: a manually+ # registered confidential client with a key set still fails closed when it+ # presents no credential at all.+ app, grant, _ = self._create_private_key_jwt_app_and_grant(is_cimd_client=False)+ response = self.post(+ "/oauth/token/",+ {+ "grant_type": "authorization_code",+ "client_id": app.client_id,+ "redirect_uri": "https://partner.example.com/callback",+ "code_verifier": self.code_verifier,+ "code": grant.code,+ },+ )+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, response.content)++ @override_settings(SITE_URL="https://us.posthog.com")+ def test_provisioning_partner_rejected_without_assertion(self):+ # A provisioning partner registers through CIMD and declares private_key_jwt too, so+ # it matches the fallback shape without needing it: partners do send assertions, and+ # the key is the credential their registration is built on. Letting them omit it+ # would hand every partner a way to downgrade itself by sending nothing.+ app, grant, _ = self._create_private_key_jwt_app_and_grant()+ app.is_provisioning_partner = True+ app.save(update_fields=["is_provisioning_partner"])+ response = self.post(+ "/oauth/token/",+ {+ "grant_type": "authorization_code",+ "client_id": app.client_id,+ "redirect_uri": "https://partner.example.com/callback",+ "code_verifier": self.code_verifier,+ "code": grant.code,+ },+ )+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, response.content)++ @freeze_time("2025-01-01 00:00:00")+ @override_settings(SITE_URL="https://us.posthog.com")+ def test_invalid_assertion_is_not_downgraded_to_the_credentialless_fallback(self):+ # A presented assertion must be verified, never ignored: an assertion signed by a+ # key the client never published has to fail the exchange even though the same+ # client could have succeeded by sending no credential at all.+ app, grant, private_key = self._create_private_key_jwt_app_and_grant()+ _, jwks = self._signed_assertion_and_jwks(app, private_key)+ attacker_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)+ forged_assertion, _attacker_jwks = self._signed_assertion_and_jwks(app, attacker_key)++ with patch(+ "posthog.api.oauth.client_assertion.fetch_client_json_document",+ return_value=(jwks, None),+ ):+ response = self._post_assertion_exchange(app, grant, forged_assertion)++ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, response.content)++ @parameterized.expand(+ [+ ("type_omitted", {}),+ ("type_wrong", {"client_assertion_type": "urn:ietf:params:oauth:grant-type:jwt-bearer"}),+ ]+ )+ @override_settings(SITE_URL="https://us.posthog.com")+ def test_assertion_with_bad_type_is_rejected_not_downgraded(self, _name, type_fields):+ # A request carrying `client_assertion` with a missing or wrong assertion type must+ # fail closed, not ride the credential-less fallback: keying the fallback on+ # successful assertion resolution instead of raw field presence would let it+ # through unverified while stamping the funnel as assertion adoption.app, grant, _ = self._create_private_key_jwt_app_and_grant()response = self.post("/oauth/token/",@@ -775,6 +875,22 @@ class TestOAuthAPI(APIBaseTest):"redirect_uri": "https://partner.example.com/callback","code_verifier": self.code_verifier,"code": grant.code,+ "client_assertion": "not-a-resolvable-assertion",+ **type_fields,+ },+ )+ self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, response.content)++ @override_settings(SITE_URL="https://us.posthog.com")+ def test_credentialless_cimd_private_key_jwt_client_cannot_revoke(self):+ # The validator is shared with /oauth/revoke/, which carries no grant_type, so the+ # fallback's grant-type gate is what keeps revocation on the declared method.+ app, _, _ = self._create_private_key_jwt_app_and_grant()+ response = self.post(+ "/oauth/revoke/",+ {+ "client_id": app.client_id,+ "token": "any-token-value",},)self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED, response.content)diff --git a/posthog/api/oauth/views.py b/posthog/api/oauth/views.pyindex 496fd784b557..3192a3f4aaca 100644--- a/posthog/api/oauth/views.py+++ b/posthog/api/oauth/views.py@@ -405,6 +405,76 @@ class OAuthValidator(OAuth2Validator):request.client = appreturn request.client+ def client_authentication_required(self, request, *args, **kwargs):+ """Route assertions to verification, and let credential-less CIMD private_key_jwt+ clients fall back to public PKCE semantics on code and refresh exchanges.++ Keyed on the raw ``client_assertion`` field, not on whether it resolves: any+ presented assertion, including one whose ``client_assertion_type`` is missing or+ wrong, requires authentication and so gets verified rather than ignored. Without+ that, an invalid assertion would silently downgrade into a successful bare-public+ exchange, and the ``client_auth_method`` funnel stamp (also keyed on the raw+ field) would count unverified traffic as assertion adoption.++ The credential-less fallback exists because a CIMD client's auth method is+ partner-declared metadata we re-read hourly, and registration marks a+ private_key_jwt declarer confidential. Enforcing that declaration locks out a+ partner whose runtime still authenticates with ``none`` (because it never re-reads+ our server metadata to learn we accept assertions) from every code and refresh+ exchange, in place and with no operator involved on either side. PKCE remains the+ enforced baseline for the fallback, exactly as for any public client. The+ grant-type gate in ``_credentialless_cimd_private_key_jwt_client`` keeps the+ fallback off revocation, which shares this validator; the agentic provisioning+ endpoints keep requiring the declared method, and partners there demonstrably+ send assertions.+ """+ if getattr(request, "client_assertion", None):+ return True+ if self._credentialless_cimd_private_key_jwt_client(request) is not None:+ return False+ return super().client_authentication_required(request, *args, **kwargs)++ def authenticate_client_id(self, request_client_id, request, *args, **kwargs):+ """The library rejects any confidential client here; permit the credential-less+ CIMD private_key_jwt shape that client_authentication_required routed this way.++ This is the point a fallback exchange is accepted, so the stale-metadata refresh+ rides on it just as it does on the assertion path: without the enqueue, a client+ living on credential-less refresh grants would keep stale scopes and config+ forever."""+ if super().authenticate_client_id(request_client_id, request, *args, **kwargs):+ return True+ app = self._credentialless_cimd_private_key_jwt_client(request)+ if app is None:+ return False+ if app.cimd_metadata_url:+ self._enqueue_cimd_metadata_refresh(app.cimd_metadata_url, app.client_id)+ return True++ def _credentialless_cimd_private_key_jwt_client(self, request) -> OAuthApplication | None:+ """The shape the public-PKCE fallback accepts: a code or refresh exchange for a+ CIMD private_key_jwt client presenting no credential of any kind. Any presented+ credential (assertion, secret, Basic auth) disqualifies the request so it+ authenticates or fails, and the grant-type gate excludes requests without a token+ grant, which is how revocation stays on the declared method.++ Provisioning partners are excluded. They register through CIMD and declare+ private_key_jwt too, so they match this shape without needing it: they do send+ assertions, and the key is the credential their registration is built on. Including+ them would hand every partner a way to downgrade itself by sending nothing."""+ if getattr(request, "grant_type", None) not in ("authorization_code", "refresh_token"):+ return None+ if getattr(request, "client_assertion", None):+ return None+ if self._extract_basic_auth(request):+ return None+ if getattr(request, "client_secret", None):+ return None+ app = self._load_application(getattr(request, "client_id", None) or "", request)+ if app is not None and app.is_cimd_client and app.uses_private_key_jwt_auth:+ return None if app.is_provisioning_partner else app+ return None+def authenticate_client(self, request, *args, **kwargs):"""Authenticate a confidential client, adding ``private_key_jwt`` (RFC 7523).@@ -417,12 +487,32 @@ class OAuthValidator(OAuth2Validator):return Truereturn super().authenticate_client(request, *args, **kwargs)- def _authenticate_client_assertion(self, request) -> bool:- assertion = resolve_client_assertion(+ @staticmethod+ def _enqueue_cimd_metadata_refresh(cimd_metadata_url: str, client_id: str) -> None:+ """Token and refresh exchanges never pass through validate_client_id, which is+ where a CIMD document is normally re-read, so a client living on refresh grants+ alone would otherwise keep a stale auth method or key source forever.+ Best-effort: a broker outage must not fail an otherwise valid exchange."""+ try:+ enqueue_cimd_refresh_if_stale(cimd_metadata_url)+ except Exception as e:+ logger.warning(+ "oauth_cimd_refresh_enqueue_error",+ client_id=client_id,+ error=str(e),+ error_type=type(e).__name__,+ )++ @staticmethod+ def _resolve_request_assertion(request) -> tuple[str, str] | None:+ return resolve_client_assertion(getattr(request, "client_assertion", None) or "",getattr(request, "client_assertion_type", None) or "",getattr(request, "client_id", None) or "",)++ def _authenticate_client_assertion(self, request) -> bool:+ assertion = self._resolve_request_assertion(request)if assertion is None:return False@@ -432,19 +522,7 @@ class OAuthValidator(OAuth2Validator):return Falseif app.is_cimd_client and app.cimd_metadata_url:- # Token and refresh exchanges never pass through validate_client_id, which is- # where a CIMD document is normally re-read, so a client living on refresh- # grants alone would otherwise keep a stale auth method or key source forever.- # Best-effort: a broker outage must not fail an otherwise valid exchange.- try:- enqueue_cimd_refresh_if_stale(app.cimd_metadata_url)- except Exception as e:- logger.warning(- "oauth_cimd_refresh_enqueue_error",- client_id=client_id,- error=str(e),- error_type=type(e).__name__,- )+ self._enqueue_cimd_metadata_refresh(app.cimd_metadata_url, client_id)try:verify_client_assertion(@@ -1489,12 +1567,27 @@ class OAuthTokenView(TokenView):RFC 6749 requires x-www-form-urlencoded, but this endpoint also accepts application/json for convenience."""+ @staticmethod+ def _request_client_auth_method(request) -> str:+ """Which client-authentication method the token request presented, regardless of+ whether it verified. Stamped onto the funnel events because a client registered for+ multiple acceptable methods (a CIMD private_key_jwt client is registered public yet+ may send assertions) is only readable from what its traffic actually carries: a+ sustained switch from "none" to "client_assertion" is the analytics signal that+ assertion enforcement can be tightened for that client."""+ if request.POST.get("client_assertion"):+ return "client_assertion"+ if request.POST.get("client_secret") or request.headers.get("Authorization", "").startswith("Basic "):+ return "client_secret"+ return "none"+@staticmethoddef _capture_token_issued(access_token: OAuthAccessToken,grant_type: str,scoped_organizations: list,scoped_teams: list,+ client_auth_method: str | None = None,) -> None:"""The last step of the authorization funnel. `oauth_authorization_granted` withouta matching `oauth_token_issued` means the client never redeemed its code."""@@ -1504,6 +1597,7 @@ class OAuthTokenView(TokenView):"granted_scope_count": len((access_token.scope or "").split()),"has_scoped_organizations": bool(scoped_organizations),"has_scoped_teams": bool(scoped_teams),+ **({"client_auth_method": client_auth_method} if client_auth_method else {}),**(get_region_info() or {}),}if access_token.application:@@ -1522,7 +1616,9 @@ class OAuthTokenView(TokenView):)@staticmethod- def _capture_token_rejected(grant_type: str, client_id: str, error: str) -> None:+ def _capture_token_rejected(+ grant_type: str, client_id: str, error: str, client_auth_method: str | None = None+ ) -> None:"""The token exchange has no authenticated user, so this keys on the client id —enough to tell "the client never came back for a token" apart from "it came backand we refused", which the authorization events alone cannot distinguish.@@ -1536,6 +1632,7 @@ class OAuthTokenView(TokenView):"client_id": client_id,# Personless: the client id is not a user, and one person per client would be noise."$process_person_profile": False,+ **({"client_auth_method": client_auth_method} if client_auth_method else {}),**(get_region_info() or {}),}try:@@ -1627,6 +1724,7 @@ class OAuthTokenView(TokenView):client_id = request.POST.get("client_id", "")client_id_prefix = client_id[:8] if client_id else "unknown"+ client_auth_method = self._request_client_auth_method(request)redirect_uri = request.POST.get("redirect_uri", "")logger.info("oauth_token_request",@@ -1647,7 +1745,7 @@ class OAuthTokenView(TokenView):client_id_prefix=client_id_prefix,redirect_uri=redirect_uri,)- self._capture_token_rejected(grant_type, client_id, "invalid_grant")+ self._capture_token_rejected(grant_type, client_id, "invalid_grant", client_auth_method)return JsonResponse({"error": "invalid_grant",@@ -1668,7 +1766,7 @@ class OAuthTokenView(TokenView):redirect_uri=redirect_uri,error=str(e),)- self._capture_token_rejected(grant_type, client_id, "temporarily_unavailable")+ self._capture_token_rejected(grant_type, client_id, "temporarily_unavailable", client_auth_method)return _temporarily_unavailable_response()except RedisError as e:# Client authentication reads Redis on the private_key_jwt path (JWKS cache, jti@@ -1721,7 +1819,9 @@ class OAuthTokenView(TokenView):response_data["scoped_teams"] = scoped_teamsresponse_data["scoped_organizations"] = scoped_organizations- self._capture_token_issued(access_token, grant_type, scoped_organizations, scoped_teams)+ self._capture_token_issued(+ access_token, grant_type, scoped_organizations, scoped_teams, client_auth_method+ )if region_info := get_region_info():response_data.update(region_info)@@ -1743,7 +1843,7 @@ class OAuthTokenView(TokenView):response["Content-Type"] = "application/json"if response.status_code != 200:- self._capture_token_rejected(grant_type, client_id, _token_error_code(response))+ self._capture_token_rejected(grant_type, client_id, _token_error_code(response), client_auth_method)return responsediff --git a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambrindex fc82245aaf04..aa1c1357f100 100644--- a/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr+++ b/posthog/hogql/test/__snapshots__/test_property_skip_indexes.ambr@@ -7,14 +7,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_dmat_string_no_skip_indexes[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_0_eq'''SELECT count() AS `count()`@@ -23,14 +15,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '0'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_1_neq'''SELECT count() AS `count()`@@ -39,14 +23,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_1_neq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '0'), 1))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_2_lt'''SELECT count() AS `count()`@@ -55,14 +31,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_2_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_3_gt'''SELECT count() AS `count()`@@ -71,14 +39,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_3_gt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_4_icontains'''SELECT count() AS `count()`@@ -87,14 +47,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_4_icontains[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%0%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_5_is_set'''SELECT count() AS `count()`@@ -103,14 +55,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_5_is_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNotNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_6_is_not_set'''SELECT count() AS `count()`@@ -119,14 +63,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_6_is_not_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_7_in_multi'''SELECT count() AS `count()`@@ -135,14 +71,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_json_only__no_skip_indexes_used_7_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('0', '1')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_lt_typed_datetime_property'''SELECT count() AS `count()`@@ -151,14 +79,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_lt_typed_datetime_property[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(parseDateTime64BestEffortOrNull(if(notEquals(toJSONString(events.properties.^lt_datetime_prop), '{}'), toJSONString(events.properties.^lt_datetime_prop), if(isNull(events.properties.lt_datetime_prop), NULL, if(startsWith(dynamicType(events.properties.lt_datetime_prop), 'DateTime'), replaceOne(toString(events.properties.lt_datetime_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.lt_datetime_prop), 'Array'), startsWith(dynamicType(events.properties.lt_datetime_prop), 'Map'), startsWith(dynamicType(events.properties.lt_datetime_prop), 'Tuple')), toJSONString(events.properties.lt_datetime_prop), toString(events.properties.lt_datetime_prop))))), 6, 'UTC'), toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_lt_typed_numeric_property'''SELECT count() AS `count()`@@ -167,14 +87,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_lt_typed_numeric_property[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), 'Float64'), 5), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_0_eq'''SELECT count() AS `count()`@@ -183,14 +95,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_1_in_multi'''SELECT count() AS `count()`@@ -199,14 +103,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_1_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_2_in_with_sentinel'''SELECT count() AS `count()`@@ -215,14 +111,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_2_in_with_sentinel[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('5', '')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_3_lt'''SELECT count() AS `count()`@@ -231,14 +119,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_bloom_filter_3_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_0_eq'''SELECT count() AS `count()`@@ -247,14 +127,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_1_lt'''SELECT count() AS `count()`@@ -263,14 +135,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_1_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_2_gt'''SELECT count() AS `count()`@@ -279,14 +143,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_2_gt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_3_in_multi'''SELECT count() AS `count()`@@ -295,14 +151,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_3_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_4_icontains_no_isnotnull'''SELECT count() AS `count()`@@ -311,14 +159,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_4_icontains_no_isnotnull[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%5%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_5_regex'''SELECT count() AS `count()`@@ -327,14 +167,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_minmax_5_regex[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(match(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '[0-9]'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_ngrambf_lower_0_icontains_long'''SELECT count() AS `count()`@@ -343,14 +175,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_ngrambf_lower_0_icontains_long[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%value_that_is_long_enough%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_ngrambf_lower_1_icontains_null_sentinel'''SELECT count() AS `count()`@@ -359,14 +183,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_non_nullable_ngrambf_lower_1_icontains_null_sentinel[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%null%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_0_eq'''SELECT count() AS `count()`@@ -375,14 +191,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_1_in_multi'''SELECT count() AS `count()`@@ -391,14 +199,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_1_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_2_neq'''SELECT count() AS `count()`@@ -407,14 +207,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_2_neq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 1))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_3_not_in'''SELECT count() AS `count()`@@ -423,14 +215,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_3_not_in[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notIn(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')), 1))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_4_lt'''SELECT count() AS `count()`@@ -439,14 +223,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_4_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_5_gt'''SELECT count() AS `count()`@@ -455,14 +231,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_5_gt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_6_icontains'''SELECT count() AS `count()`@@ -471,14 +239,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_6_icontains[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%5%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_7_is_set'''SELECT count() AS `count()`@@ -487,14 +247,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_bloom_filter_7_is_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNotNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_0_eq'''SELECT count() AS `count()`@@ -503,14 +255,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_1_neq'''SELECT count() AS `count()`@@ -519,14 +263,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_1_neq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notEquals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 1))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_2_lt'''SELECT count() AS `count()`@@ -535,14 +271,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_2_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_3_gt'''SELECT count() AS `count()`@@ -551,14 +279,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_3_gt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_4_lte'''SELECT count() AS `count()`@@ -567,14 +287,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_4_lte[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(lessOrEquals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_5_gte'''SELECT count() AS `count()`@@ -583,14 +295,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_5_gte[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greaterOrEquals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_6_in_multi'''SELECT count() AS `count()`@@ -599,14 +303,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_6_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_7_icontains_with_isnotnull'''SELECT count() AS `count()`@@ -615,14 +311,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_7_icontains_with_isnotnull[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%5%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_8_regex'''SELECT count() AS `count()`@@ -631,14 +319,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_8_regex[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(match(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '[0-9]'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_0_int'''SELECT count() AS `count()`@@ -647,14 +327,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_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(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), 5), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_1_float'''SELECT count() AS `count()`@@ -663,14 +335,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_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(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), 5.5), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_2_datetime'''SELECT count() AS `count()`@@ -679,14 +343,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_non_string_constant_against_string_column_errors_2_datetime[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), toDateTime64('2024-01-15 10:30:00.000000', 6, 'UTC')), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_looking_strings_compare_lexically'''SELECT events.distinct_id AS distinct_id@@ -707,26 +363,6 @@use_hive_partitioning=0'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_numeric_looking_strings_compare_lexically[new_events_schema]- '''- SELECT events.distinct_id AS distinct_id- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '500'), 0))- ORDER BY events.distinct_id ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_0_string_pure_alpha'''SELECT count() AS `count()`@@ -735,14 +371,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_0_string_pure_alpha[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), 'apple'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_numeric_looking'''SELECT count() AS `count()`@@ -751,14 +379,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_1_string_numeric_looking[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_2_string_date_looking'''SELECT count() AS `count()`@@ -767,14 +387,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_2_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(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '2024-01-15'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_minmax_lt_string_constant_flavors_3_string_iso_datetime_looking'''SELECT count() AS `count()`@@ -783,14 +395,6 @@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()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '2024-01-15T10:30:00Z'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_0_icontains_long'''SELECT count() AS `count()`@@ -799,14 +403,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_0_icontains_long[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%value_that_is_long_enough%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_1_not_icontains'''SELECT count() AS `count()`@@ -815,14 +411,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_1_not_icontains[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notILike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%abc%'), 1))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_2_eq'''SELECT count() AS `count()`@@ -831,14 +419,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_2_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_3_lt'''SELECT count() AS `count()`@@ -847,14 +427,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_3_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_4_regex'''SELECT count() AS `count()`@@ -863,14 +435,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_4_regex[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(match(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), 'value_that_is_long_enough'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_0_eq_string'''SELECT count() AS `count()`@@ -879,14 +443,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_0_eq_string[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_1_is_set'''SELECT count() AS `count()`@@ -895,14 +451,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_1_is_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNotNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_2_is_not_set'''SELECT count() AS `count()`@@ -911,14 +459,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_2_is_not_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNull(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_3_in_multi'''SELECT count() AS `count()`@@ -927,14 +467,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_3_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_4_lt'''SELECT count() AS `count()`@@ -943,14 +475,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_4_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_property_group_optimized_5_icontains'''SELECT count() AS `count()`@@ -959,14 +483,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_property_group_optimized_5_icontains[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.properties.^test_prop), '{}'), toJSONString(events.properties.^test_prop), if(isNull(events.properties.test_prop), NULL, if(startsWith(dynamicType(events.properties.test_prop), 'DateTime'), replaceOne(toString(events.properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.test_prop), 'Array'), startsWith(dynamicType(events.properties.test_prop), 'Map'), startsWith(dynamicType(events.properties.test_prop), 'Tuple')), toJSONString(events.properties.test_prop), toString(events.properties.test_prop)))))), '%5%'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_typed_datetime_mat_col_uses_minmax_index'''SELECT count() AS `count()`@@ -975,14 +491,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_typed_datetime_mat_col_uses_minmax_index[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(parseDateTime64BestEffortOrNull(if(notEquals(toJSONString(events.properties.^typed_datetime_prop), '{}'), toJSONString(events.properties.^typed_datetime_prop), if(isNull(events.properties.typed_datetime_prop), NULL, if(startsWith(dynamicType(events.properties.typed_datetime_prop), 'DateTime'), replaceOne(toString(events.properties.typed_datetime_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.typed_datetime_prop), 'Array'), startsWith(dynamicType(events.properties.typed_datetime_prop), 'Map'), startsWith(dynamicType(events.properties.typed_datetime_prop), 'Tuple')), toJSONString(events.properties.typed_datetime_prop), toString(events.properties.typed_datetime_prop))))), 6, 'UTC'), '2024-01-05 00:00:00'), 0))- LIMIT 50000- '''-# ---# name: TestEventPropertySkipIndexes.test_typed_numeric_mat_col_uses_minmax_index'''SELECT count() AS `count()`@@ -991,14 +499,6 @@LIMIT 50000'''# ----# name: TestEventPropertySkipIndexes.test_typed_numeric_mat_col_uses_minmax_index[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^typed_numeric_prop), '{}'), toJSONString(events.properties.^typed_numeric_prop), if(isNull(events.properties.typed_numeric_prop), NULL, if(startsWith(dynamicType(events.properties.typed_numeric_prop), 'DateTime'), replaceOne(toString(events.properties.typed_numeric_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.typed_numeric_prop), 'Array'), startsWith(dynamicType(events.properties.typed_numeric_prop), 'Map'), startsWith(dynamicType(events.properties.typed_numeric_prop), 'Tuple')), toJSONString(events.properties.typed_numeric_prop), toString(events.properties.typed_numeric_prop))))), 'Float64'), 5), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_0_eq'''SELECT count() AS `count()`@@ -1007,14 +507,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_1_in_multi'''SELECT count() AS `count()`@@ -1023,14 +515,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_1_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_2_not_in'''SELECT count() AS `count()`@@ -1039,14 +523,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_2_not_in[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(notIn(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), tuple('2', '5')), 1))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_3_lt'''SELECT count() AS `count()`@@ -1055,14 +531,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_bloom_filter_3_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_0_eq'''SELECT count() AS `count()`@@ -1071,14 +539,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_0_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_1_lt'''SELECT count() AS `count()`@@ -1087,14 +547,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_1_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_2_gt'''SELECT count() AS `count()`@@ -1103,14 +555,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_2_gt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(greater(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_3_in_multi'''SELECT count() AS `count()`@@ -1119,14 +563,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_3_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_4_icontains_with_isnotnull'''SELECT count() AS `count()`@@ -1135,14 +571,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_minmax_4_icontains_with_isnotnull[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop)))))), '%5%'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_0_icontains_long'''SELECT count() AS `count()`@@ -1151,14 +579,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_0_icontains_long[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(ilike(toString(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop)))))), '%value_that_is_long_enough%'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_1_eq'''SELECT count() AS `count()`@@ -1167,14 +587,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_mat_col_nullable_ngrambf_lower_1_eq[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_0_eq_string'''SELECT count() AS `count()`@@ -1183,14 +595,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_0_eq_string[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_1_is_set'''SELECT count() AS `count()`@@ -1199,14 +603,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_1_is_set[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), isNotNull(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop)))))))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_2_in_multi'''SELECT count() AS `count()`@@ -1215,14 +611,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_2_in_multi[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), tuple('2', '5')))- LIMIT 50000- '''-# ---# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_3_lt'''SELECT count() AS `count()`@@ -1231,14 +619,6 @@LIMIT 50000'''# ----# name: TestPersonOnEventsPropertySkipIndexes.test_property_group_optimized_3_lt[new_events_schema]- '''- SELECT count() AS `count()`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(less(if(notEquals(toJSONString(events.person_properties.^test_prop), '{}'), toJSONString(events.person_properties.^test_prop), if(isNull(events.person_properties.test_prop), NULL, if(startsWith(dynamicType(events.person_properties.test_prop), 'DateTime'), replaceOne(toString(events.person_properties.test_prop), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.test_prop), 'Array'), startsWith(dynamicType(events.person_properties.test_prop), 'Map'), startsWith(dynamicType(events.person_properties.test_prop), 'Tuple')), toJSONString(events.person_properties.test_prop), toString(events.person_properties.test_prop))))), '5'), 0))- LIMIT 50000- '''-# ---# name: TestPersonPropertySkipIndexes.test_mat_col_nullable_bloom_filter_0_eq'''SELECT count() AS `count()`diff --git a/posthog/hogql/test/__snapshots__/test_query.ambr b/posthog/hogql/test/__snapshots__/test_query.ambrindex e7ea49c6ee71..4457bd4e3208 100644--- a/posthog/hogql/test/__snapshots__/test_query.ambr+++ b/posthog/hogql/test/__snapshots__/test_query.ambr@@ -27,34 +27,6 @@OFFSET 0'''# ----# name: TestQuery.test_clickhouse_timestamp_handling[new_events_schema]- '''- -- ClickHouse- SELECT events__fingerprint_issue_state.issue_id AS id, count(DISTINCT events.uuid) AS occurrences, count(DISTINCT nullIf(events.`$session_id`, %(hogql_val_0)s)) AS sessions, count(DISTINCT events.distinct_id) AS users, max(toTimeZone(events.timestamp, %(hogql_val_1)s)) AS last_seen, min(toTimeZone(events.timestamp, %(hogql_val_2)s)) AS first_seen, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_3)s, toStartOfHour(toTimeZone(events.timestamp, %(hogql_val_4)s)), toStartOfHour(now64(6, %(hogql_val_5)s)))), x), range(24))) AS volumeDay, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_6)s, toStartOfDay(toTimeZone(events.timestamp, %(hogql_val_7)s)), toStartOfDay(now64(6, %(hogql_val_8)s)))), x), range(31))) AS volumeMonth, reverse(arrayMap(x -> countEqual(groupArray(dateDiff(%(hogql_val_9)s, toStartOfHour(toTimeZone(events.timestamp, %(hogql_val_10)s)), toStartOfHour(now64(6, %(hogql_val_11)s)))), x), range(168))) AS customVolume- FROM events_json AS events LEFT OUTER JOIN (- SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash, toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_id), error_tracking_fingerprint_issue_state.version), 1)) AS issue_id- FROM error_tracking_fingerprint_issue_state- WHERE equals(error_tracking_fingerprint_issue_state.team_id, 99999)- GROUP BY fp_hash- HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__fingerprint_issue_state ON equals(cityHash64(events.properties.`$exception_fingerprint`), events__fingerprint_issue_state.fp_hash)- WHERE and(equals(events.team_id, 99999), and(equals(events.event, %(hogql_val_12)s), isNotNull(events__fingerprint_issue_state.issue_id), or(and(greater(toTimeZone(events.timestamp, %(hogql_val_13)s), parseDateTime64BestEffort(%(hogql_val_14)s, 6, %(hogql_val_15)s)), less(toTimeZone(events.timestamp, %(hogql_val_16)s), parseDateTime64BestEffort(%(hogql_val_17)s, 6, %(hogql_val_18)s))), and(greater(toTimeZone(events.timestamp, %(hogql_val_19)s), toDateTime(%(hogql_val_20)s, %(hogql_val_21)s)), less(toTimeZone(events.timestamp, %(hogql_val_22)s), toDateTime64(%(hogql_val_23)s, 6, %(hogql_val_24)s))))))- GROUP BY events__fingerprint_issue_state.issue_id- ORDER BY occurrences DESC- LIMIT 51- OFFSET 0- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT issue_id AS id, count(DISTINCT uuid) AS occurrences, count(DISTINCT nullIf($session_id, '')) AS sessions, count(DISTINCT distinct_id) AS users, max(timestamp) AS last_seen, min(timestamp) AS first_seen, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('hour', toStartOfHour(timestamp), toStartOfHour(now()))), x), range(24))) AS volumeDay, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('day', toStartOfDay(timestamp), toStartOfDay(now()))), x), range(31))) AS volumeMonth, reverse(arrayMap(x -> countEqual(groupArray(dateDiff('hour', toStartOfHour(timestamp), toStartOfHour(now()))), x), range(168))) AS customVolume- FROM events- WHERE and(equals(event, '$exception'), isNotNull(issue_id), or(and(greater(timestamp, toDateTime('2025-02-10 23:53:03.175952+02:30')), less(timestamp, toDateTime('2025-02-11 23:53'))), and(greater(timestamp, toDateTime('2025-02-12 23:53:03')), less(timestamp, toDateTime('2025-02-13 23:53:03.175952')))))- GROUP BY issue_id- ORDER BY occurrences DESC- LIMIT 51- OFFSET 0- '''-# ---# name: TestQuery.test_hogql_arrays'''-- ClickHouse@@ -87,26 +59,6 @@LIMIT 1'''# ----# name: TestQuery.test_hogql_groupby_unnecessary_ifnull[new_events_schema]- '''- -- ClickHouse- SELECT toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS timestamp, count() AS cnt- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(timestamp, addDays(today(), -10)))- GROUP BY timestamp- HAVING greater(cnt, 10)- LIMIT 1- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT toDate(timestamp) AS timestamp, count() AS cnt- FROM events- WHERE greaterOrEquals(timestamp, addDays(today(), -10))- GROUP BY timestamp- HAVING greater(cnt, 10)- LIMIT 1- '''-# ---# name: TestQuery.test_hogql_lambdas'''-- ClickHouse@@ -153,40 +105,6 @@LIMIT 100'''# ----# name: TestQuery.test_hogql_proper_ifnull[new_events_schema]- '''- -- ClickHouse- WITH latest_events AS (- SELECT events.distinct_id AS distinct_id, argMax(events.properties.`$os_version`, toTimeZone(events.timestamp, %(hogql_val_0)s)) AS latest_os_version- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(equals(events.properties.`$os`, %(hogql_val_1)s), isNotNull(events.properties.`$os`)), greaterOrEquals(events.timestamp, minus(now64(6, %(hogql_val_2)s), toIntervalDay(30))))- GROUP BY events.distinct_id), major_versions AS (- SELECT latest_events.distinct_id AS distinct_id, latest_events.latest_os_version AS latest_os_version, splitByChar(%(hogql_val_3)s, ifNull(latest_events.latest_os_version, %(hogql_val_4)s))[1] AS major_version- FROM latest_events)- SELECT major_versions.major_version AS major_version, count() AS user_count, round(divide(multiply(100, count()), sum(count()) OVER ()), 2) AS percentage- FROM major_versions- WHERE in(major_versions.major_version, tuple(%(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s))- GROUP BY major_versions.major_version- ORDER BY major_versions.major_version ASC- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- WITH latest_events AS (- SELECT distinct_id, argMax(properties.$os_version, timestamp) AS latest_os_version- FROM events- WHERE and(equals(properties.$os, 'iOS'), greaterOrEquals(timestamp, minus(now(), toIntervalDay(30))))- GROUP BY distinct_id), major_versions AS (- SELECT distinct_id, latest_os_version, splitByChar('.', ifNull(latest_os_version, ''))[1] AS major_version- FROM latest_events)- SELECT major_version, count() AS user_count, round(divide(multiply(100, count()), sum(count()) OVER ()), 2) AS percentage- FROM major_versions- WHERE in(major_version, tuple('17', '18', '26'))- GROUP BY major_version- ORDER BY major_version ASC- LIMIT 100- '''-# ---# name: TestQuery.test_hogql_query_filters'''-- ClickHouse@@ -237,56 +155,6 @@LIMIT 100'''# ----# name: TestQuery.test_hogql_query_filters[new_events_schema.1]- '''-- SELECT event, distinct_id- FROM events- WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), equals(properties.index, '4'))- LIMIT 100- '''-# ----# name: TestQuery.test_hogql_query_filters[new_events_schema.2]- '''- -- ClickHouse- SELECT events.event AS event, events.distinct_id AS distinct_id- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.distinct_id, %(hogql_val_0)s), and(ifNull(equals(if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))), %(hogql_val_1)s), 0), lessOrEquals(events.timestamp, toDateTime64('2020-01-02 23:59:59.999999', 6, 'UTC')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC'))))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, distinct_id- FROM events- WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), and(equals(properties.index, '4'), lessOrEquals(timestamp, toDateTime('2020-01-02 23:59:59.999999')), greaterOrEquals(timestamp, toDateTime('2020-01-01 00:00:00.000000'))))- LIMIT 100- '''-# ----# name: TestQuery.test_hogql_query_filters[new_events_schema.3]- '''-- SELECT event, distinct_id- FROM events- WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), and(equals(properties.index, '4'), lessOrEquals(timestamp, toDateTime('2020-01-02 23:59:59.999999')), greaterOrEquals(timestamp, toDateTime('2020-01-01 00:00:00.000000'))))- LIMIT 100- '''-# ----# name: TestQuery.test_hogql_query_filters[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, events.distinct_id AS distinct_id- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.distinct_id, %(hogql_val_0)s), ifNull(equals(if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))), %(hogql_val_1)s), 0))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, distinct_id- FROM events- WHERE and(equals(distinct_id, 'RANDOM_TEST_ID::UUID'), equals(properties.index, '4'))- LIMIT 100- '''-# ---# name: TestQuery.test_hogql_query_filters_alias'''-- ClickHouse@@ -303,22 +171,6 @@LIMIT 100'''# ----# name: TestQuery.test_hogql_query_filters_alias[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, e.distinct_id AS distinct_id- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(e.properties.^random_uuid), '{}'), toJSONString(e.properties.^random_uuid), if(isNull(e.properties.random_uuid), NULL, if(startsWith(dynamicType(e.properties.random_uuid), 'DateTime'), replaceOne(toString(e.properties.random_uuid), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.random_uuid), 'Array'), startsWith(dynamicType(e.properties.random_uuid), 'Map'), startsWith(dynamicType(e.properties.random_uuid), 'Tuple')), toJSONString(e.properties.random_uuid), toString(e.properties.random_uuid))))), %(hogql_val_0)s), 0))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, distinct_id- FROM events AS e- WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')- LIMIT 100- '''-# ---# name: TestQuery.test_hogql_query_filters_session_date_range'''-- ClickHouse@@ -399,28 +251,6 @@LIMIT 100'''# ----# name: TestQuery.test_hogql_union_all_limits[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events- WHERE equals(events.team_id, 99999)- LIMIT 100 UNION ALL- SELECT events.event AS event- FROM events_json AS events- WHERE equals(events.team_id, 99999)- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events- LIMIT 100 UNION ALL- SELECT event- FROM events- LIMIT 100- '''-# ---# name: TestQuery.test_hogql_unnecessary_ifnull'''-- ClickHouse@@ -437,22 +267,6 @@LIMIT 1'''# ----# name: TestQuery.test_hogql_unnecessary_ifnull[new_events_schema]- '''- -- ClickHouse- SELECT toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS timestamp, JSONExtractInt(ifNull(if(notEquals(toJSONString(events.properties.^field), '{}'), toJSONString(events.properties.^field), if(isNull(events.properties.field), NULL, if(startsWith(dynamicType(events.properties.field), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.field), ' ', 'T')), ''), '"'), toJSONString(events.properties.field)))), '')) AS json_int- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(timestamp, addDays(today(), -10)), equals(json_int, 17))- LIMIT 1- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT toDate(timestamp) AS timestamp, JSONExtractInt(properties, 'field') AS json_int- FROM events- WHERE and(greaterOrEquals(timestamp, addDays(today(), -10)), equals(json_int, 17))- LIMIT 1- '''-# ---# name: TestQuery.test_join_with_property_materialized_session_id'''-- ClickHouse@@ -485,38 +299,6 @@LIMIT 10'''# ----# name: TestQuery.test_join_with_property_materialized_session_id[new_events_schema.1]- '''-- SELECT e.event, s.session_id- FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$session_id)- WHERE notEquals(e.properties.$session_id, NULL)- LIMIT 10- '''-# ----# name: TestQuery.test_join_with_property_materialized_session_id[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, s.session_id AS session_id- FROM (- SELECT e.event AS event, e.properties.`$session_id` AS `properties__$session_id`- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), isNotNull(e.properties.`$session_id`))- LIMIT 10) AS e LEFT JOIN (- SELECT session_replay_events.session_id AS session_id- FROM session_replay_events- WHERE equals(session_replay_events.team_id, 99999)- GROUP BY session_replay_events.session_id) AS s ON equals(s.session_id, e.`properties__$session_id`)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT e.event, s.session_id- FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$session_id)- WHERE notEquals(e.properties.$session_id, NULL)- LIMIT 10- '''-# ---# name: TestQuery.test_join_with_property_not_materialized'''-- ClickHouse@@ -549,38 +331,6 @@LIMIT 10'''# ----# name: TestQuery.test_join_with_property_not_materialized[new_events_schema.1]- '''-- SELECT e.event, s.session_id- FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$$$session_id)- WHERE notEquals(e.properties.$$$session_id, NULL)- LIMIT 10- '''-# ----# name: TestQuery.test_join_with_property_not_materialized[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, s.session_id AS session_id- FROM (- SELECT e.event AS event, if(notEquals(toJSONString(e.properties.^`$$$session_id`), '{}'), toJSONString(e.properties.^`$$$session_id`), if(isNull(e.properties.`$$$session_id`), NULL, if(startsWith(dynamicType(e.properties.`$$$session_id`), 'DateTime'), replaceOne(toString(e.properties.`$$$session_id`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$$$session_id`), 'Array'), startsWith(dynamicType(e.properties.`$$$session_id`), 'Map'), startsWith(dynamicType(e.properties.`$$$session_id`), 'Tuple')), toJSONString(e.properties.`$$$session_id`), toString(e.properties.`$$$session_id`))))) AS `properties__$$$session_id`- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), isNotNull(if(notEquals(toJSONString(e.properties.^`$$$session_id`), '{}'), toJSONString(e.properties.^`$$$session_id`), if(isNull(e.properties.`$$$session_id`), NULL, if(startsWith(dynamicType(e.properties.`$$$session_id`), 'DateTime'), replaceOne(toString(e.properties.`$$$session_id`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$$$session_id`), 'Array'), startsWith(dynamicType(e.properties.`$$$session_id`), 'Map'), startsWith(dynamicType(e.properties.`$$$session_id`), 'Tuple')), toJSONString(e.properties.`$$$session_id`), toString(e.properties.`$$$session_id`)))))))- LIMIT 10) AS e LEFT JOIN (- SELECT session_replay_events.session_id AS session_id- FROM session_replay_events- WHERE equals(session_replay_events.team_id, 99999)- GROUP BY session_replay_events.session_id) AS s ON equals(s.session_id, e.`properties__$$$session_id`)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT e.event, s.session_id- FROM events AS e LEFT JOIN session_replay_events AS s ON equals(s.session_id, e.properties.$$$session_id)- WHERE notEquals(e.properties.$$$session_id, NULL)- LIMIT 10- '''-# ---# name: TestQuery.test_prop_cohort_basic'''-- ClickHouse@@ -643,39 +393,11 @@LIMIT 100'''# ----# name: TestQuery.test_prop_cohort_basic[new_events_schema.1]- '''- -- ClickHouse- SELECT events.event AS event, count(*) AS `count(*)`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.person_id, (- SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX))- GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version- HAVING greater(sum(cohortpeople.sign), 0))))- GROUP BY events.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, count(*)- FROM events- WHERE in(person_id, (- SELECT person_id- FROM raw_cohort_people- WHERE equals(cohort_id, XX)- GROUP BY person_id, cohort_id, version- HAVING greater(sum(sign), 0)))- GROUP BY event- LIMIT 100- '''-# ----# name: TestQuery.test_prop_cohort_basic[new_events_schema]+# name: TestQuery.test_prop_cohort_static'''-- ClickHouseSELECT events.event AS event, count() AS `count()`- FROM events_json AS events LEFT OUTER JOIN (+ FROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 99999)@@ -683,11 +405,9 @@HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)WHERE and(equals(events.team_id, 99999), in(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (- SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX))- GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version- HAVING greater(sum(cohortpeople.sign), 0))))+ SELECT person_static_cohort.person_id AS person_id+ FROM person_static_cohort+ WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX)))))GROUP BY events.eventLIMIT 100SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0@@ -697,45 +417,13 @@FROM eventsWHERE in(person_id, (SELECT person_id- FROM raw_cohort_people- WHERE equals(cohort_id, XX)- GROUP BY person_id, cohort_id, version- HAVING greater(sum(sign), 0)))+ FROM static_cohort_people+ WHERE equals(cohort_id, XX)))GROUP BY eventLIMIT 100'''# ----# name: TestQuery.test_prop_cohort_static- '''- -- ClickHouse- SELECT events.event AS event, count() AS `count()`- FROM events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), in(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (- SELECT person_static_cohort.person_id AS person_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX)))))- GROUP BY events.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, count()- FROM events- WHERE in(person_id, (- SELECT person_id- FROM static_cohort_people- WHERE equals(cohort_id, XX)))- GROUP BY event- LIMIT 100- '''-# ----# name: TestQuery.test_prop_cohort_static.1+# name: TestQuery.test_prop_cohort_static.1'''-- ClickHouseSELECT events.event AS event, count(*) AS `count(*)`@@ -759,60 +447,6 @@LIMIT 100'''# ----# name: TestQuery.test_prop_cohort_static[new_events_schema.1]- '''- -- ClickHouse- SELECT events.event AS event, count(*) AS `count(*)`- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.person_id, (- SELECT person_static_cohort.person_id AS person_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX)))))- GROUP BY events.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, count(*)- FROM events- WHERE in(person_id, (- SELECT person_id- FROM static_cohort_people- WHERE equals(cohort_id, XX)))- GROUP BY event- LIMIT 100- '''-# ----# name: TestQuery.test_prop_cohort_static[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, count() AS `count()`- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), in(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (- SELECT person_static_cohort.person_id AS person_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX)))))- GROUP BY events.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, count()- FROM events- WHERE in(person_id, (- SELECT person_id- FROM static_cohort_people- WHERE equals(cohort_id, XX)))- GROUP BY event- LIMIT 100- '''-# ---# name: TestQuery.test_query'''-- ClickHouse@@ -831,24 +465,6 @@LIMIT 100'''# ----# name: TestQuery.test_query[new_events_schema]- '''- -- ClickHouse- SELECT count() AS `count()`, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^random_uuid), '{}'), toJSONString(events.properties.^random_uuid), if(isNull(events.properties.random_uuid), NULL, if(startsWith(dynamicType(events.properties.random_uuid), 'DateTime'), replaceOne(toString(events.properties.random_uuid), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_uuid), 'Array'), startsWith(dynamicType(events.properties.random_uuid), 'Map'), startsWith(dynamicType(events.properties.random_uuid), 'Tuple')), toJSONString(events.properties.random_uuid), toString(events.properties.random_uuid))))), %(hogql_val_0)s), 0))- GROUP BY events.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT count(), event- FROM events- WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')- GROUP BY event- LIMIT 100- '''-# ---# name: TestQuery.test_query_distinct'''-- ClickHouse@@ -894,27 +510,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_e_pdi[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_0)s) AS timestamp, e__pdi.distinct_id AS distinct_id, e__pdi.person_id AS person_id- FROM events_json AS e INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS e__pdi ON equals(e.distinct_id, e__pdi.distinct_id)- WHERE equals(e.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, e.timestamp, e.pdi.distinct_id, pdi.person_id- FROM events AS e- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_first_to_persons'''-- ClickHouse@@ -946,37 +541,6 @@LIMIT 100'''# ----# name: TestQuery.test_query_joins_events_first_to_persons[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, persons.properties___email AS email- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id)- WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_3)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT events.event, persons.properties.email- FROM events JOIN persons ON equals(events.person_id, persons.id)- WHERE equals(events.event, 'pageview')- LIMIT 100- '''-# ---# name: TestQuery.test_query_joins_events_pdi'''-- ClickHouse@@ -998,27 +562,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_pdi[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_0)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi.person_id AS person_id- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id)- WHERE equals(events.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, pdi.distinct_id, pdi.person_id- FROM events- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_pdi_e_person_properties'''-- ClickHouse@@ -1049,36 +592,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_pdi_e_person_properties[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, e__pdi.distinct_id AS distinct_id, e__pdi__person.properties___sneaky_mail AS sneaky_mail- FROM events_json AS e INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS e__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS e__pdi ON equals(e.distinct_id, e__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS e__pdi__person ON equals(e__pdi.e__pdi___person_id, e__pdi__person.id)- WHERE equals(e.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, e.timestamp, pdi.distinct_id, e.pdi.person.properties.sneaky_mail- FROM events AS e- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_pdi_person'''-- ClickHouse@@ -1106,33 +619,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_pdi_person[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_2)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi__person.id AS id- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS events__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.events__pdi___person_id, events__pdi__person.id)- WHERE equals(events.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, pdi.distinct_id, pdi.person.id- FROM events- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_pdi_person_properties'''-- ClickHouse@@ -1163,36 +649,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_pdi_person_properties[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_3)s) AS timestamp, events__pdi.distinct_id AS distinct_id, events__pdi__person.properties___sneaky_mail AS sneaky_mail- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS events__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.events__pdi___person_id, events__pdi__person.id)- WHERE equals(events.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, pdi.distinct_id, pdi.person.properties.sneaky_mail- FROM events- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_person_properties'''-- ClickHouse@@ -1223,36 +679,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_person_properties[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, e__pdi__person.properties___sneaky_mail AS sneaky_mail- FROM events_json AS e INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS e__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS e__pdi ON equals(e.distinct_id, e__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS e__pdi__person ON equals(e__pdi.e__pdi___person_id, e__pdi__person.id)- WHERE equals(e.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, e.timestamp, e.pdi.person.properties.sneaky_mail- FROM events AS e- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_events_person_properties_in_aggregration'''-- ClickHouse@@ -1285,38 +711,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_events_person_properties_in_aggregration[new_events_schema]- '''- -- ClickHouse- SELECT s__pdi__person.properties___sneaky_mail AS sneaky_mail, count() AS `count()`- FROM events_json AS s INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS s__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS s__pdi ON equals(s.distinct_id, s__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS s__pdi__person ON equals(s__pdi.s__pdi___person_id, s__pdi__person.id)- WHERE equals(s.team_id, 99999)- GROUP BY s__pdi__person.properties___sneaky_mail- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT s.pdi.person.properties.sneaky_mail, count()- FROM events AS s- GROUP BY s.pdi.person.properties.sneaky_mail- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_lazy_on_both_sides'''-- ClickHouse@@ -1338,76 +732,21 @@SETTINGS optimize_aggregation_in_order=1) AS e2__override ON equals(e2.distinct_id, e2__override.distinct_id)WHERE equals(e2.team_id, 99999)) AS e2 ON equals(if(not(empty(e1__override.distinct_id)), e1__override.person_id, e1.person_id), e2.person_id)WHERE and(equals(e1.team_id, 99999), equals(e1.event, %(hogql_val_0)s), equals(e2.event, %(hogql_val_1)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT e1.event, e2.event- FROM events AS e1 JOIN events AS e2 ON equals(e1.person_id, e2.person_id)- WHERE and(equals(e1.event, 'pageview'), equals(e2.event, 'click'))- LIMIT 100- '''-# ----# name: TestQuery.test_query_joins_lazy_on_both_sides[new_events_schema]- '''- -- ClickHouse- SELECT e1.event, e2.event AS event- FROM events_json AS e1 LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS e1__override ON equals(e1.distinct_id, e1__override.distinct_id) JOIN (- SELECT e2.distinct_id AS distinct_id, e2.event AS event, e2.person_id AS event_person_id, if(not(empty(e2__override.distinct_id)), e2__override.person_id, e2.person_id) AS person_id- FROM events_json AS e2 LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS e2__override ON equals(e2.distinct_id, e2__override.distinct_id)- WHERE equals(e2.team_id, 99999)) AS e2 ON equals(if(not(empty(e1__override.distinct_id)), e1__override.person_id, e1.person_id), e2.person_id)- WHERE and(equals(e1.team_id, 99999), equals(e1.event, %(hogql_val_0)s), equals(e2.event, %(hogql_val_1)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT e1.event, e2.event- FROM events AS e1 JOIN events AS e2 ON equals(e1.person_id, e2.person_id)- WHERE and(equals(e1.event, 'pageview'), equals(e2.event, 'click'))- LIMIT 100- '''-# ----# name: TestQuery.test_query_joins_pdi- '''- -- ClickHouse- SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_0)s) AS timestamp, pdi.person_id AS person_id- FROM events AS e INNER JOIN (- SELECT person_distinct_id2.distinct_id AS distinct_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)) AS pdi ON equals(e.distinct_id, pdi.distinct_id)- WHERE equals(e.team_id, 99999)- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, pdi.person_id- FROM events AS e INNER JOIN (- SELECT distinct_id, argMax(person_id, version) AS person_id- FROM raw_person_distinct_ids- GROUP BY distinct_id- HAVING equals(argMax(is_deleted, version), 0)) AS pdi ON equals(e.distinct_id, pdi.distinct_id)+ LIMIT 100+ SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0++ -- HogQL+ SELECT e1.event, e2.event+ FROM events AS e1 JOIN events AS e2 ON equals(e1.person_id, e2.person_id)+ WHERE and(equals(e1.event, 'pageview'), equals(e2.event, 'click'))LIMIT 100'''# ----# name: TestQuery.test_query_joins_pdi[new_events_schema]+# name: TestQuery.test_query_joins_pdi'''-- ClickHouseSELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_0)s) AS timestamp, pdi.person_id AS person_id- FROM events_json AS e INNER JOIN (+ FROM events AS e INNER JOIN (SELECT person_distinct_id2.distinct_id AS distinct_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_idFROM person_distinct_id2WHERE equals(person_distinct_id2.team_id, 99999)@@ -1511,35 +850,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_joins_persons_to_events[new_events_schema]- '''- -- ClickHouse- SELECT persons.id AS id, events.event AS event- FROM (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS persons JOIN (- SELECT events.distinct_id AS distinct_id, events.event AS event, events.person_id AS event_person_id, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE equals(events.team_id, 99999)) AS events ON equals(persons.id, events.person_id)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT persons.id, events.event- FROM persons JOIN events ON equals(persons.id, events.person_id)- LIMIT 10- '''-# ---# name: TestQuery.test_query_joins_simple'''-- ClickHouse@@ -1570,36 +880,6 @@LIMIT 100'''# ----# name: TestQuery.test_query_joins_simple[new_events_schema]- '''- -- ClickHouse- SELECT e.event AS event, toTimeZone(e.timestamp, %(hogql_val_3)s) AS timestamp, pdi.distinct_id AS distinct_id, p.id AS id, p.properties___sneaky_mail AS sneaky_mail- FROM events_json AS e LEFT JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 99999)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS pdi ON equals(pdi.distinct_id, e.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS p ON equals(p.id, pdi.person_id)- WHERE equals(e.team_id, 99999)- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, pdi.distinct_id, p.id, p.properties.sneaky_mail- FROM events AS e LEFT JOIN person_distinct_ids AS pdi ON equals(pdi.distinct_id, e.distinct_id) LEFT JOIN persons AS p ON equals(p.id, pdi.person_id)- LIMIT 100- '''-# ---# name: TestQuery.test_query_person_distinct_ids'''-- ClickHouse@@ -1650,36 +930,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_select_person_with_joins_without_poe[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_3)s) AS timestamp, events__person.id AS id, events__person.properties___sneaky_mail AS sneaky_mail- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version), (- SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1)))))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, person.id, person.properties.sneaky_mail- FROM events- LIMIT 10- '''-# ---# name: TestQuery.test_query_select_person_with_poe_without_joins'''-- ClickHouse@@ -1695,21 +945,6 @@LIMIT 10'''# ----# name: TestQuery.test_query_select_person_with_poe_without_joins[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event, toTimeZone(events.timestamp, %(hogql_val_0)s) AS timestamp, events.person_id AS id, if(notEquals(toJSONString(events.person_properties.^sneaky_mail), '{}'), toJSONString(events.person_properties.^sneaky_mail), if(isNull(events.person_properties.sneaky_mail), NULL, if(startsWith(dynamicType(events.person_properties.sneaky_mail), 'DateTime'), replaceOne(toString(events.person_properties.sneaky_mail), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.sneaky_mail), 'Array'), startsWith(dynamicType(events.person_properties.sneaky_mail), 'Map'), startsWith(dynamicType(events.person_properties.sneaky_mail), 'Tuple')), toJSONString(events.person_properties.sneaky_mail), toString(events.person_properties.sneaky_mail))))) AS sneaky_mail- FROM events_json AS events- WHERE equals(events.team_id, 99999)- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event, timestamp, person.id, person.properties.sneaky_mail- FROM events- LIMIT 10- '''-# ---# name: TestQuery.test_select_person_on_events'''-- ClickHouse@@ -1727,23 +962,6 @@LIMIT 10'''# ----# name: TestQuery.test_select_person_on_events[new_events_schema]- '''- -- ClickHouse- SELECT if(notEquals(toJSONString(s.person_properties.^sneaky_mail), '{}'), toJSONString(s.person_properties.^sneaky_mail), if(isNull(s.person_properties.sneaky_mail), NULL, if(startsWith(dynamicType(s.person_properties.sneaky_mail), 'DateTime'), replaceOne(toString(s.person_properties.sneaky_mail), ' ', 'T'), if(or(startsWith(dynamicType(s.person_properties.sneaky_mail), 'Array'), startsWith(dynamicType(s.person_properties.sneaky_mail), 'Map'), startsWith(dynamicType(s.person_properties.sneaky_mail), 'Tuple')), toJSONString(s.person_properties.sneaky_mail), toString(s.person_properties.sneaky_mail))))) AS sneaky_mail, count() AS `count()`- FROM events_json AS s- WHERE equals(s.team_id, 99999)- GROUP BY if(notEquals(toJSONString(s.person_properties.^sneaky_mail), '{}'), toJSONString(s.person_properties.^sneaky_mail), if(isNull(s.person_properties.sneaky_mail), NULL, if(startsWith(dynamicType(s.person_properties.sneaky_mail), 'DateTime'), replaceOne(toString(s.person_properties.sneaky_mail), ' ', 'T'), if(or(startsWith(dynamicType(s.person_properties.sneaky_mail), 'Array'), startsWith(dynamicType(s.person_properties.sneaky_mail), 'Map'), startsWith(dynamicType(s.person_properties.sneaky_mail), 'Tuple')), toJSONString(s.person_properties.sneaky_mail), toString(s.person_properties.sneaky_mail)))))- LIMIT 10- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT poe.properties.sneaky_mail, count()- FROM events AS s- GROUP BY poe.properties.sneaky_mail- LIMIT 10- '''-# ---# name: TestQuery.test_subquery'''-- ClickHouse@@ -1768,30 +986,6 @@LIMIT 100'''# ----# name: TestQuery.test_subquery[new_events_schema]- '''- -- ClickHouse- SELECT cnt AS cnt, event AS event- FROM (- SELECT count() AS cnt, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^random_uuid), '{}'), toJSONString(events.properties.^random_uuid), if(isNull(events.properties.random_uuid), NULL, if(startsWith(dynamicType(events.properties.random_uuid), 'DateTime'), replaceOne(toString(events.properties.random_uuid), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_uuid), 'Array'), startsWith(dynamicType(events.properties.random_uuid), 'Map'), startsWith(dynamicType(events.properties.random_uuid), 'Tuple')), toJSONString(events.properties.random_uuid), toString(events.properties.random_uuid))))), %(hogql_val_0)s), 0))- GROUP BY events.event)- GROUP BY cnt, event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT cnt, event- FROM (- SELECT count() AS cnt, event- FROM events- WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')- GROUP BY event)- GROUP BY cnt, event- LIMIT 100- '''-# ---# name: TestQuery.test_subquery_alias'''-- ClickHouse@@ -1816,30 +1010,6 @@LIMIT 100'''# ----# name: TestQuery.test_subquery_alias[new_events_schema]- '''- -- ClickHouse- SELECT c.cnt AS cnt, c.event AS event- FROM (- SELECT count(*) AS cnt, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), ifNull(equals(if(notEquals(toJSONString(events.properties.^random_uuid), '{}'), toJSONString(events.properties.^random_uuid), if(isNull(events.properties.random_uuid), NULL, if(startsWith(dynamicType(events.properties.random_uuid), 'DateTime'), replaceOne(toString(events.properties.random_uuid), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.random_uuid), 'Array'), startsWith(dynamicType(events.properties.random_uuid), 'Map'), startsWith(dynamicType(events.properties.random_uuid), 'Tuple')), toJSONString(events.properties.random_uuid), toString(events.properties.random_uuid))))), %(hogql_val_0)s), 0))- GROUP BY events.event) AS c- GROUP BY c.cnt, c.event- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT cnt, event- FROM (- SELECT count(*) AS cnt, event- FROM events- WHERE equals(properties.random_uuid, 'RANDOM_TEST_ID::UUID')- GROUP BY event) AS c- GROUP BY cnt, event- LIMIT 100- '''-# ---# name: TestQuery.test_tuple_access'''-- ClickHouse@@ -1871,37 +1041,6 @@LIMIT 100'''# ----# name: TestQuery.test_tuple_access[new_events_schema]- '''- -- ClickHouse- SELECT col_a AS col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r- FROM (- SELECT col_a AS col_a, groupArray(tuple(col_b, col_c)) AS g- FROM (- SELECT if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))) AS col_a, events.event AS col_b, count() AS col_c- FROM events_json AS events- WHERE equals(events.team_id, 99999)- GROUP BY if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))), events.event)- GROUP BY col_a)- GROUP BY col_a- ORDER BY col_a ASC- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r- FROM (- SELECT col_a, groupArray(tuple(col_b, col_c)) AS g- FROM (- SELECT properties.index AS col_a, event AS col_b, count() AS col_c- FROM events- GROUP BY properties.index, event)- GROUP BY col_a)- GROUP BY col_a- ORDER BY col_a ASC- LIMIT 100- '''-# ---# name: TestQuery.test_with_pivot_table_1_level'''-- ClickHouse@@ -1939,43 +1078,6 @@LIMIT 100'''# ----# name: TestQuery.test_with_pivot_table_1_level[new_events_schema]- '''- -- ClickHouse- WITH PIVOT_TABLE_COL_ABC AS (- SELECT if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))) AS col_a, events.event AS col_b, count() AS col_c- FROM events_json AS events- WHERE equals(events.team_id, 99999)- GROUP BY if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))), events.event), PIVOT_FUNCTION_1 AS (- SELECT PIVOT_TABLE_COL_ABC.col_a AS col_a, groupArray(tuple(PIVOT_TABLE_COL_ABC.col_b, PIVOT_TABLE_COL_ABC.col_c)) AS g- FROM PIVOT_TABLE_COL_ABC- GROUP BY PIVOT_TABLE_COL_ABC.col_a), PIVOT_FUNCTION_2 AS (- SELECT PIVOT_FUNCTION_1.col_a AS col_a, arrayZip((sumMap((PIVOT_FUNCTION_1.g).1, (PIVOT_FUNCTION_1.g).2) AS x).1, x.2) AS r- FROM PIVOT_FUNCTION_1- GROUP BY PIVOT_FUNCTION_1.col_a)- SELECT PIVOT_FUNCTION_2.col_a AS col_a, PIVOT_FUNCTION_2.r AS r- FROM PIVOT_FUNCTION_2- ORDER BY PIVOT_FUNCTION_2.col_a ASC- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- WITH PIVOT_TABLE_COL_ABC AS (- SELECT properties.index AS col_a, event AS col_b, count() AS col_c- FROM events- GROUP BY properties.index, event), PIVOT_FUNCTION_1 AS (- SELECT col_a, groupArray(tuple(col_b, col_c)) AS g- FROM PIVOT_TABLE_COL_ABC- GROUP BY col_a), PIVOT_FUNCTION_2 AS (- SELECT col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r- FROM PIVOT_FUNCTION_1- GROUP BY col_a)- SELECT col_a, r- FROM PIVOT_FUNCTION_2- ORDER BY col_a ASC- LIMIT 100- '''-# ---# name: TestQuery.test_with_pivot_table_2_levels'''-- ClickHouse@@ -2017,44 +1119,3 @@LIMIT 100'''# ----# name: TestQuery.test_with_pivot_table_2_levels[new_events_schema]- '''- -- ClickHouse- WITH PIVOT_TABLE_COL_ABC AS (- SELECT if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))) AS col_a, events.event AS col_b, count() AS col_c- FROM events_json AS events- WHERE equals(events.team_id, 99999)- GROUP BY if(notEquals(toJSONString(events.properties.^index), '{}'), toJSONString(events.properties.^index), if(isNull(events.properties.index), NULL, if(startsWith(dynamicType(events.properties.index), 'DateTime'), replaceOne(toString(events.properties.index), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.index), 'Array'), startsWith(dynamicType(events.properties.index), 'Map'), startsWith(dynamicType(events.properties.index), 'Tuple')), toJSONString(events.properties.index), toString(events.properties.index))))), events.event), PIVOT_FUNCTION_1 AS (- SELECT PIVOT_TABLE_COL_ABC.col_a AS col_a, groupArray(tuple(PIVOT_TABLE_COL_ABC.col_b, PIVOT_TABLE_COL_ABC.col_c)) AS g- FROM PIVOT_TABLE_COL_ABC- GROUP BY PIVOT_TABLE_COL_ABC.col_a), PIVOT_FUNCTION_2 AS (- SELECT PIVOT_FUNCTION_1.col_a AS col_a, arrayZip((sumMap((PIVOT_FUNCTION_1.g).1, (PIVOT_FUNCTION_1.g).2) AS x).1, x.2) AS r- FROM PIVOT_FUNCTION_1- GROUP BY PIVOT_FUNCTION_1.col_a), final AS (- SELECT PIVOT_FUNCTION_2.col_a AS col_a, PIVOT_FUNCTION_2.r AS r- FROM PIVOT_FUNCTION_2)- SELECT final.col_a AS col_a, final.r AS r- FROM final- ORDER BY final.col_a ASC- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- WITH PIVOT_TABLE_COL_ABC AS (- SELECT properties.index AS col_a, event AS col_b, count() AS col_c- FROM events- GROUP BY properties.index, event), PIVOT_FUNCTION_1 AS (- SELECT col_a, groupArray(tuple(col_b, col_c)) AS g- FROM PIVOT_TABLE_COL_ABC- GROUP BY col_a), PIVOT_FUNCTION_2 AS (- SELECT col_a, arrayZip((sumMap((g).1, (g).2) AS x).1, x.2) AS r- FROM PIVOT_FUNCTION_1- GROUP BY col_a), final AS (- SELECT col_a, r- FROM PIVOT_FUNCTION_2)- SELECT col_a, r- FROM final- ORDER BY col_a ASC- LIMIT 100- '''-# ---diff --git a/posthog/hogql/transforms/test/__snapshots__/test_events_predicate_pushdown.ambr b/posthog/hogql/transforms/test/__snapshots__/test_events_predicate_pushdown.ambrindex 1af17f61b208..d066a7c7791d 100644--- a/posthog/hogql/transforms/test/__snapshots__/test_events_predicate_pushdown.ambr+++ b/posthog/hogql/transforms/test/__snapshots__/test_events_predicate_pushdown.ambr@@ -15,22 +15,6 @@LIMIT 50'''# ----# name: TestEventsPredicatePushdownExecution.test_exec_aliased_events_timestamp_filter_with_session_join[new_events_schema]- '''-- SELECT e.event AS event, e__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(e.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, e.event AS event- FROM events_json AS e- WHERE and(equals(e.team_id, 420), greaterOrEquals(e.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), less(e.timestamp, toDateTime64(%(hogql_val_3)s, 6, %(hogql_val_4)s)))- LIMIT 50) AS e LEFT JOIN (- SELECT dateDiff(%(hogql_val_5)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_6)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_7)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_8)s, toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(%(hogql_val_9)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.__pd_expr_0, e__session.session_id_v7)- LIMIT 50- '''-# ---# name: TestEventsPredicatePushdownExecution.test_exec_timestamp_filter_with_session_join'''@@ -47,22 +31,6 @@LIMIT 50'''# ----# name: TestEventsPredicatePushdownExecution.test_exec_timestamp_filter_with_session_join[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), less(events.timestamp, toDateTime64(%(hogql_val_3)s, 6, %(hogql_val_4)s)))- LIMIT 50) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_5)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_6)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_7)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_8)s, toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(%(hogql_val_9)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50- '''-# ---# name: TestEventsPredicatePushdownTransform.test_bare_timestamp_with_select_alias_pushes_down'''@@ -79,22 +47,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_bare_timestamp_with_select_alias_pushes_down[new_events_schema]- '''-- SELECT events.event AS event, events.__pd_expr_0 AS timestamp, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toTimeZone(toTimeZone(events.timestamp, %(hogql_val_0)s), %(hogql_val_1)s) AS __pd_expr_0, toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_2)s)) AS __pd_expr_1, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(toTimeZone(toTimeZone(events.timestamp, %(hogql_val_3)s), %(hogql_val_4)s), %(hogql_val_5)s), lessOrEquals(toTimeZone(toTimeZone(events.timestamp, %(hogql_val_6)s), %(hogql_val_7)s), today()))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_8)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_9)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_10)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_11)s, toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(today(), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_1, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_events_with_alias_and_session_join'''@@ -111,22 +63,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_events_with_alias_and_session_join[new_events_schema]- '''-- SELECT e.event AS event, e__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(e.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, e.event AS event- FROM events_json AS e- WHERE and(equals(e.team_id, 420), greaterOrEquals(e.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000) AS e LEFT JOIN (- SELECT dateDiff(%(hogql_val_3)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_4)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_5)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_6)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.__pd_expr_0, e__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_events_with_session_join_and_timestamp_filter'''@@ -143,22 +79,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_events_with_session_join_and_timestamp_filter[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_3)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_4)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_5)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_6)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_events_without_join_no_pushdown'''@@ -168,15 +88,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_events_without_join_no_pushdown[new_events_schema]- '''-- SELECT events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_events_without_where_no_pushdown'''@@ -190,19 +101,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_events_without_where_no_pushdown[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM events_json AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_0)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_1)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_2)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE equals(raw_sessions.team_id, 420)- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_3)s)), events__session.session_id_v7)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_multiple_poe_fields_with_session_join'''@@ -219,22 +117,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_multiple_poe_fields_with_session_join[new_events_schema]- '''-- SELECT events.event AS event, events.person_id AS id, events.person_properties AS properties, events.__pd_expr_0 AS created_at, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toTimeZone(events.person_created_at, %(hogql_val_0)s) AS __pd_expr_0, toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_1)s)) AS __pd_expr_1, events.event AS event, events.person_id AS person_id, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null', JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS person_properties- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_4)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_5)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_6)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_7)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_1, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_multiple_pushable_predicates'''@@ -251,22 +133,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_multiple_pushable_predicates[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), equals(events.event, %(hogql_val_3)s))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_4)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_5)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_6)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_7)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_0_explicit_join'''@@ -280,19 +146,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_0_explicit_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_1_inner_join'''@@ -306,19 +159,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_1_inner_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events INNER JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_2_cross_join'''@@ -332,19 +172,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_2_cross_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events CROSS JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_3_right_join'''@@ -358,19 +185,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_3_right_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events RIGHT JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_4_right_outer_join'''@@ -384,19 +198,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_4_right_outer_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events RIGHT OUTER JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_5_full_outer_join'''@@ -410,19 +211,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_5_full_outer_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events FULL OUTER JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_6_full_join'''@@ -436,19 +224,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_non_row_preserving_join_skips_pushdown_6_full_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM events_json AS events FULL JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_0)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_poe_created_at_with_session_join'''@@ -465,22 +240,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_poe_created_at_with_session_join[new_events_schema]- '''-- SELECT events.event AS event, events.__pd_expr_0 AS created_at, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toTimeZone(events.person_created_at, %(hogql_val_0)s) AS __pd_expr_0, toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_1)s)) AS __pd_expr_1, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_4)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_5)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_6)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_7)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_1, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_poe_id_with_session_join'''@@ -497,22 +256,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_poe_id_with_session_join[new_events_schema]- '''-- SELECT events.person_id AS id, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.person_id AS person_id- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_3)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_4)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_5)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_6)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_poe_properties_with_session_join'''@@ -529,22 +272,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_poe_properties_with_session_join[new_events_schema]- '''-- SELECT events.event AS event, events.person_properties AS properties, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event, concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null', JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS person_properties- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_3)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_4)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_5)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_6)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_row_preserving_join_pushes_timestamp_down_0_left_join'''@@ -561,22 +288,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_row_preserving_join_pushes_timestamp_down_0_left_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM (- SELECT events.`$session_id` AS `$session_id`, events.uuid AS uuid- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_2)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_row_preserving_join_pushes_timestamp_down_1_left_outer_join'''@@ -593,22 +304,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_row_preserving_join_pushes_timestamp_down_1_left_outer_join[new_events_schema]- '''-- SELECT sessions.session_id AS session_id, events.uuid AS uuid- FROM (- SELECT events.`$session_id` AS `$session_id`, events.uuid AS uuid- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000) AS events LEFT OUTER JOIN (- SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_2)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS sessions ON equals(events.`$session_id`, sessions.session_id)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_session_duration_filter_declines'''@@ -622,19 +317,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_session_duration_filter_declines[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM events_json AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_0)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_1)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_2)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_3)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_4)s)), events__session.session_id_v7)- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s)), greater(events__session.`$session_duration`, 0))- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_simple_events_with_person_join'''@@ -659,30 +341,6 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_simple_events_with_person_join[new_events_schema]- '''-- SELECT events.event AS event, events__person.id AS id- FROM (- SELECT events.distinct_id AS distinct_id, events.event AS event, events.person_id AS person_id- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greater(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000) AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_2)s), person.version), plus(now64(6, %(hogql_val_3)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- LIMIT 50000- '''-# ---# name: TestEventsPredicatePushdownTransform.test_subquery_with_pushdown'''@@ -703,23 +361,3 @@LIMIT 50000'''# ----# name: TestEventsPredicatePushdownTransform.test_subquery_with_pushdown[new_events_schema]- '''-- SELECT event AS event, avg(`$session_duration`) AS `avg($session_duration)`- FROM (- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), or(equals(events.event, %(hogql_val_3)s), equals(events.event, %(hogql_val_4)s)))- LIMIT 100) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_5)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_6)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_7)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_8)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 100)- GROUP BY event- LIMIT 50000- '''-# ---diff --git a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambrindex 89fdff689fe9..5d3a2ce1793c 100644--- a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr+++ b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr@@ -21,28 +21,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_conjoined_dynamic[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT cohortpeople.person_id AS cohort_person_id, 1 AS matched, cohortpeople.cohort_id AS cohort_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX), equals(cohortpeople.version, 0))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_0)s), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id- FROM raw_cohort_people- WHERE and(equals(cohort_id, XX), equals(version, 0))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(and(equals(1, 1), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_conjoined_int'''-- ClickHouse@@ -65,28 +43,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_conjoined_int[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), in(person_static_cohort.cohort_id, [1, 2, 3, 4, 5 /* ... */]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id- FROM static_cohort_people- WHERE in(cohort_id, [1, 2, 3, 4, 5 /* ... */])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(equals(1, 1), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_conjoined_string'''-- ClickHouse@@ -109,28 +65,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_conjoined_string[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), in(person_static_cohort.cohort_id, [1, 2, 3, 4, 5 /* ... */]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id- FROM static_cohort_people- WHERE in(cohort_id, [1, 2, 3, 4, 5 /* ... */])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(equals(1, 1), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_deleted'''-- ClickHouse@@ -153,28 +87,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_deleted[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS person_id, 1 AS matched- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM static_cohort_people- WHERE equals(cohort_id, XX)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE equals(in_cohort__XX.matched, 1)- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_dynamic'''-- ClickHouse@@ -201,32 +113,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_dynamic[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT cohortpeople.person_id AS person_id, 1 AS matched- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX))- GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version- HAVING greater(sum(cohortpeople.sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1), equals(events.event, %(hogql_val_0)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM raw_cohort_people- WHERE equals(cohort_id, XX)- GROUP BY person_id, cohort_id, version- HAVING greater(sum(sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'))- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_same_cohort_referenced_twice'''-- ClickHouse@@ -253,32 +139,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_same_cohort_referenced_twice[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT cohortpeople.person_id AS person_id, 1 AS matched- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX))- GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version- HAVING greater(sum(cohortpeople.sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1), equals(events.event, %(hogql_val_0)s), equals(in_cohort__XX.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM raw_cohort_people- WHERE equals(cohort_id, XX)- GROUP BY person_id, cohort_id, version- HAVING greater(sum(sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'), equals(in_cohort__XX.matched, 1))- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_static'''-- ClickHouse@@ -301,28 +161,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_static[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS person_id, 1 AS matched- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM static_cohort_people- WHERE equals(cohort_id, XX)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE equals(in_cohort__XX.matched, 1)- LIMIT 100- '''-# ---# name: TestInCohort.test_in_cohort_strings'''-- ClickHouse@@ -345,28 +183,6 @@LIMIT 100'''# ----# name: TestInCohort.test_in_cohort_strings[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS person_id, 1 AS matched- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM static_cohort_people- WHERE equals(cohort_id, XX)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE equals(in_cohort__XX.matched, 1)- LIMIT 100- '''-# ---# name: TestInlineCohortLeftjoin.test_inline_conjoined_mixed_static_and_dynamic'''-- ClickHouse@@ -410,49 +226,6 @@LIMIT 100'''# ----# name: TestInlineCohortLeftjoin.test_inline_conjoined_mixed_static_and_dynamic[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), in(person_static_cohort.cohort_id, [1, 2, 3, 4, 5 /* ... */])) UNION ALL- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT persons.id AS id- FROM (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___test_prop, person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id, (- SELECT where_optimization.id AS id- FROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_3)s), person.version), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))))) AS persons- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)- ORDER BY persons.id ASC- SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_6)s), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id- FROM static_cohort_people- WHERE in(cohort_id, [1, 2, 3, 4, 5 /* ... */]) UNION ALL- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT id- FROM persons- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')- ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(and(or(equals(1, 1), equals(1, 1)), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ---# name: TestInlineCohortLeftjoin.test_inline_conjoined_off_vs_always'''-- ClickHouse@@ -533,86 +306,6 @@LIMIT 100'''# ----# name: TestInlineCohortLeftjoin.test_inline_conjoined_off_vs_always[new_events_schema.1]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT persons.id AS id- FROM (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___test_prop, person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id, (- SELECT where_optimization.id AS id- FROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_3)s), person.version), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))))) AS persons- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)- ORDER BY persons.id ASC- SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto')) UNION ALL- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT persons.id AS id- FROM (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_6)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___test_prop, person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id, (- SELECT where_optimization.id AS id- FROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), %(hogql_val_8)s), 0)))))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_9)s), person.version), plus(now64(6, %(hogql_val_10)s), toIntervalDay(1))))) AS persons- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_11)s), 0)- ORDER BY persons.id ASC- SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_12)s), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT id- FROM persons- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')- ORDER BY id ASC)) UNION ALL- SELECT id AS cohort_person_id, 1 AS matched, 99999 AS cohort_id- FROM ((- SELECT id- FROM persons- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')- ORDER BY id ASC))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(and(or(equals(1, 1), equals(1, 1)), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ----# name: TestInlineCohortLeftjoin.test_inline_conjoined_off_vs_always[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT cohortpeople.person_id AS cohort_person_id, 1 AS matched, cohortpeople.cohort_id AS cohort_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), or(and(equals(cohortpeople.cohort_id, XX), equals(cohortpeople.version, 0)), and(equals(cohortpeople.cohort_id, XX), equals(cohortpeople.version, 0))))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_0)s), equals(__in_cohort.matched, 1))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id- FROM raw_cohort_people- WHERE or(and(equals(cohort_id, XX), equals(version, 0)), and(equals(cohort_id, XX), equals(version, 0)))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id)- WHERE and(and(or(equals(1, 1), equals(1, 1)), equals(event, 'RANDOM_TEST_ID::UUID')), equals(__in_cohort.matched, 1))- LIMIT 100- '''-# ---# name: TestInlineCohortLeftjoin.test_inline_leftjoin_off_vs_always'''-- ClickHouse@@ -684,77 +377,6 @@LIMIT 100'''# ----# name: TestInlineCohortLeftjoin.test_inline_leftjoin_off_vs_always[new_events_schema.1]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT id AS person_id, 1 AS matched- FROM ((- SELECT persons.id AS id- FROM (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___test_prop, person.id AS id- FROM person- WHERE and(equals(person.team_id, 99999), in(id, (- SELECT where_optimization.id AS id- FROM person AS where_optimization- WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), %(hogql_val_2)s), 0)))))- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_3)s), person.version), plus(now64(6, %(hogql_val_4)s), toIntervalDay(1))))) AS persons- WHERE ifNull(equals(persons.properties___test_prop, %(hogql_val_5)s), 0)- ORDER BY persons.id ASC- SETTINGS optimize_aggregation_in_order=1, join_algorithm='auto'))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1), equals(events.event, %(hogql_val_6)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT id AS person_id, 1 AS matched- FROM ((- SELECT id- FROM (- SELECT tupleElement(argMax(tuple(raw_persons.properties.test_prop), raw_persons.version), 1) AS properties___test_prop, raw_persons.id AS id- FROM raw_persons- WHERE in(id, (- SELECT id- FROM raw_persons AS where_optimization- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')))- GROUP BY raw_persons.id- HAVING and(equals(tupleElement(argMax(tuple(raw_persons.is_deleted), raw_persons.version), 1), 0), less(tupleElement(argMax(tuple(raw_persons.created_at), raw_persons.version), 1), plus(now(), toIntervalDay(1))))) AS persons- WHERE equals(properties.test_prop, 'RANDOM_TEST_ID::UUID')- ORDER BY id ASC))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'))- LIMIT 100- '''-# ----# name: TestInlineCohortLeftjoin.test_inline_leftjoin_off_vs_always[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT cohortpeople.person_id AS person_id, 1 AS matched- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, XX))- GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version- HAVING greater(sum(cohortpeople.sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1), equals(events.event, %(hogql_val_0)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM raw_cohort_people- WHERE equals(cohort_id, XX)- GROUP BY person_id, cohort_id, version- HAVING greater(sum(sign), 0)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'))- LIMIT 100- '''-# ---# name: TestInlineCohortLeftjoin.test_inline_static_always_uses_cohortpeople'''-- ClickHouse@@ -777,25 +399,3 @@LIMIT 100'''# ----# name: TestInlineCohortLeftjoin.test_inline_static_always_uses_cohortpeople[new_events_schema]- '''- -- ClickHouse- SELECT events.event AS event- FROM events_json AS events LEFT JOIN (- SELECT person_static_cohort.person_id AS person_id, 1 AS matched- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, XX))) AS in_cohort__XX ON equals(in_cohort__XX.person_id, events.person_id)- WHERE and(equals(events.team_id, 99999), equals(in_cohort__XX.matched, 1), equals(events.event, %(hogql_val_0)s))- LIMIT 100- SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0, transform_null_in=1, optimize_min_equality_disjunction_chain_length=4294967295, optimize_rewrite_aggregate_function_with_if=0, optimize_min_inequality_conjunction_chain_length=4294967295, allow_experimental_join_condition=1, use_hive_partitioning=0-- -- HogQL- SELECT event- FROM events LEFT JOIN (- SELECT person_id, 1 AS matched- FROM static_cohort_people- WHERE equals(cohort_id, XX)) AS in_cohort__XX ON equals(in_cohort__XX.person_id, person_id)- WHERE and(equals(in_cohort__XX.matched, 1), equals(event, 'RANDOM_TEST_ID::UUID'))- LIMIT 100- '''-# ---diff --git a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambrindex ec527e7dbf8c..9dc6b40382cd 100644--- a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr+++ b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr@@ -15,22 +15,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_events_session_join_with_multiple_predicates[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), less(events.timestamp, toDateTime64(%(hogql_val_3)s, 6, %(hogql_val_4)s)), equals(events.event, %(hogql_val_5)s), isNotNull(events.`$session_id`))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_6)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_7)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_8)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_9)s, toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(%(hogql_val_10)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_events_session_join_with_session_duration_filter'''@@ -44,19 +28,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_events_session_join_with_session_duration_filter[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM events_json AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_0)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_1)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_2)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_3)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_4)s)), events__session.session_id_v7)- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s)), greater(events__session.`$session_duration`, 0))- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_events_session_join_with_timestamp_filter'''@@ -73,22 +44,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_events_session_join_with_timestamp_filter[new_events_schema]- '''-- SELECT events.event AS event, events__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, events.event AS event- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), less(events.timestamp, toDateTime64(%(hogql_val_3)s, 6, %(hogql_val_4)s)))- LIMIT 50000) AS events LEFT JOIN (- SELECT dateDiff(%(hogql_val_5)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_6)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_7)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_8)s, toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(%(hogql_val_9)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(events.__pd_expr_0, events__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_events_sessions_join_with_alias'''@@ -105,22 +60,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_events_sessions_join_with_alias[new_events_schema]- '''-- SELECT e.event AS event, e__session.`$session_duration` AS `$session_duration`- FROM (- SELECT toUInt128(accurateCastOrNull(e.`$session_id`, %(hogql_val_0)s)) AS __pd_expr_0, e.event AS event- FROM events_json AS e- WHERE and(equals(e.team_id, 420), greaterOrEquals(e.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)), equals(e.event, %(hogql_val_3)s))- LIMIT 50000) AS e LEFT JOIN (- SELECT dateDiff(%(hogql_val_4)s, min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_5)s)), max(toTimeZone(raw_sessions.max_timestamp, %(hogql_val_6)s))) AS `$session_duration`, raw_sessions.session_id_v7 AS session_id_v7- FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(%(hogql_val_7)s, toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS e__session ON equals(e.__pd_expr_0, e__session.session_id_v7)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_lazy_join_on_lazy_table'''@@ -157,23 +96,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_lazy_join_on_lazy_table_with_person_properties[new_events_schema]- '''-- SELECT persons__events.event AS event- FROM (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS persons___properties___email, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS persons LEFT JOIN (- SELECT events.event AS event, event AS persons__events___event- FROM events_json AS events- WHERE equals(events.team_id, 420)) AS persons__events ON equals(persons.persons___properties___email, persons__events.persons__events___event)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_lazy_join_on_lazy_table_with_properties'''@@ -228,27 +150,6 @@LIMIT 10'''# ----# name: TestLazyJoins.test_resolve_lazy_table_as_table_in_join[new_events_schema]- '''-- SELECT events.event AS event, events.distinct_id AS distinct_id, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, persons.properties___email AS email- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___email, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id))- WHERE equals(events.team_id, 420)- LIMIT 10- '''-# ---# name: TestLazyJoins.test_resolve_lazy_table_indirect_duplicate_references'''@@ -270,27 +171,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_table_indirect_duplicate_references[new_events_schema]- '''-- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, events__person.properties AS properties- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT argMax(person.properties, person.version) AS properties, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_table_indirectly_referenced'''@@ -312,27 +192,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_table_indirectly_referenced[new_events_schema]- '''-- SELECT events__person.id AS id- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables'''@@ -348,21 +207,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables[new_events_schema]- '''-- SELECT events.event AS event, events__pdi.person_id AS person_id- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 420)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables_one_level_properties'''@@ -418,21 +262,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables_traversed_fields[new_events_schema]- '''-- SELECT events.event AS event, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables_two_levels'''@@ -454,27 +283,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables_two_levels[new_events_schema]- '''-- SELECT events.event AS event, events__pdi__person.id AS id- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS events__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 420)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.events__pdi___person_id, events__pdi__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties'''@@ -496,27 +304,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties[new_events_schema]- '''-- SELECT events.event AS event, events__pdi__person.`properties___$browser` AS `$browser`- FROM events_json AS events INNER JOIN (- SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS events__pdi___person_id, argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id- FROM person_distinct_id2- WHERE equals(person_distinct_id2.team_id, 420)- GROUP BY person_distinct_id2.distinct_id- HAVING equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS `properties___$browser`, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.events__pdi___person_id, events__pdi__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties_duplicate'''@@ -538,27 +325,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties_duplicate[new_events_schema]- '''-- SELECT events.event AS event, events__person.properties AS properties, events__person.properties___name AS name- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___name, argMax(person.properties, person.version) AS properties, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_traversed'''@@ -580,27 +346,6 @@LIMIT 50000'''# ----# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_traversed[new_events_schema]- '''-- SELECT events.event AS event, events__person.id AS id- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestLazyJoins.test_select_count_from_lazy_table'''diff --git a/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr b/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambrindex 89fda61384ec..b248041e0e8c 100644--- a/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr+++ b/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr@@ -29,19 +29,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_group_boolean_property_types[new_events_schema]- '''-- SELECT ifNull(equals(accurateCastOrNull(transform(toString(events__group_0.properties___group_boolean), %(hogql_val_2)s, %(hogql_val_3)s, NULL), %(hogql_val_4)s), 1), 0), ifNull(equals(accurateCastOrNull(transform(toString(events__group_0.properties___group_boolean), %(hogql_val_5)s, %(hogql_val_6)s, NULL), %(hogql_val_7)s), 0), 0), isNull(accurateCastOrNull(transform(toString(events__group_0.properties___group_boolean), %(hogql_val_8)s, %(hogql_val_9)s, NULL), %(hogql_val_10)s))- FROM events_json AS events LEFT JOIN (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, %(hogql_val_1)s)), 1) AS properties___group_boolean, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 420), equals(index, 0))- GROUP BY groups.group_type_index, groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_group_property_types'''@@ -55,19 +42,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_group_property_types[new_events_schema]- '''-- SELECT accurateCastOrNull(events__group_0.properties___inty, %(hogql_val_2)s) AS inty- FROM events_json AS events LEFT JOIN (- SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, %(hogql_val_1)s)), 1) AS properties___inty, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 420), equals(index, 0))- GROUP BY groups.group_type_index, groups.group_key) AS events__group_0 ON equals(events.`$group_0`, events__group_0.key)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_resolve_property_types_combined'''@@ -89,27 +63,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_resolve_property_types_combined[new_events_schema]- '''-- SELECT multiply(accurateCastOrNull(events.properties.`$screen_width`, %(hogql_val_4)s), events__person.properties___tickets)- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT tupleElement(argMax(tuple(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s)), person.version), 1) AS properties___tickets, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_2)s), person.version), plus(now64(6, %(hogql_val_3)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_resolve_property_types_event'''@@ -119,15 +72,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_resolve_property_types_event[new_events_schema]- '''-- SELECT multiply(accurateCastOrNull(events.properties.`$screen_width`, %(hogql_val_0)s), accurateCastOrNull(events.properties.`$screen_height`, %(hogql_val_1)s)), accurateCastOrNull(transform(toString(if(notEquals(toJSONString(events.properties.^bool), '{}'), toJSONString(events.properties.^bool), if(isNull(events.properties.bool), NULL, if(startsWith(dynamicType(events.properties.bool), 'DateTime'), replaceOne(toString(events.properties.bool), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.bool), 'Array'), startsWith(dynamicType(events.properties.bool), 'Map'), startsWith(dynamicType(events.properties.bool), 'Tuple')), toJSONString(events.properties.bool), toString(events.properties.bool)))))), %(hogql_val_2)s, %(hogql_val_3)s, NULL), %(hogql_val_4)s) AS bool- FROM events_json AS events- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_resolve_property_types_event_person_poe_off'''@@ -149,27 +93,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_resolve_property_types_event_person_poe_off[new_events_schema]- '''-- SELECT events__person.properties___provided_timestamp AS provided_timestamp- FROM events_json AS events LEFT OUTER JOIN (- SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 420)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)- SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (- SELECT tupleElement(argMax(tuple(parseDateTime64BestEffortOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), 6, %(hogql_val_1)s)), person.version), 1) AS properties___provided_timestamp, person.id AS id- FROM person- WHERE equals(person.team_id, 420)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, %(hogql_val_2)s), person.version), plus(now64(6, %(hogql_val_3)s), toIntervalDay(1))))- SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_resolve_property_types_event_person_poe_on'''@@ -179,15 +102,6 @@LIMIT 50000'''# ----# name: TestPropertyTypes.test_resolve_property_types_event_person_poe_on[new_events_schema]- '''-- SELECT parseDateTime64BestEffortOrNull(if(notEquals(toJSONString(events.person_properties.^provided_timestamp), '{}'), toJSONString(events.person_properties.^provided_timestamp), if(isNull(events.person_properties.provided_timestamp), NULL, if(startsWith(dynamicType(events.person_properties.provided_timestamp), 'DateTime'), replaceOne(toString(events.person_properties.provided_timestamp), ' ', 'T'), if(or(startsWith(dynamicType(events.person_properties.provided_timestamp), 'Array'), startsWith(dynamicType(events.person_properties.provided_timestamp), 'Map'), startsWith(dynamicType(events.person_properties.provided_timestamp), 'Tuple')), toJSONString(events.person_properties.provided_timestamp), toString(events.person_properties.provided_timestamp))))), 6, %(hogql_val_0)s) AS provided_timestamp- FROM events_json AS events- WHERE equals(events.team_id, 420)- LIMIT 50000- '''-# ---# name: TestPropertyTypes.test_resolve_property_types_person'''diff --git a/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr b/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambrindex cbea0bbfcbf7..47592059b475 100644--- a/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr+++ b/posthog/hogql/transforms/test/__snapshots__/test_state_aggregations.ambr@@ -22,29 +22,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_cohort_analysis_time_windows[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(cohort_metrics, 1)), countMerge(tupleElement(cohort_metrics, 2)), sumMerge(tupleElement(cohort_metrics, 3))) AS cohort_metrics, %(hogql_val_7)s AS cohort_period- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_0)s)), sumStateIf(1, equals(events.event, %(hogql_val_1)s))) AS cohort_metrics, %(hogql_val_2)s AS cohort_period- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_3)s, 6, %(hogql_val_4)s)), less(events.timestamp, toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(cohort_metrics, 1)), countMerge(tupleElement(cohort_metrics, 2)), sumMerge(tupleElement(cohort_metrics, 3))) AS cohort_metrics, %(hogql_val_15)s AS cohort_period- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_8)s)), sumStateIf(1, equals(events.event, %(hogql_val_9)s))) AS cohort_metrics, %(hogql_val_10)s AS cohort_period- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_11)s, 6, %(hogql_val_12)s)), less(events.timestamp, toDateTime64(%(hogql_val_13)s, 6, %(hogql_val_14)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(cohort_metrics, 1)), countMerge(tupleElement(cohort_metrics, 2)), sumMerge(tupleElement(cohort_metrics, 3))) AS cohort_metrics, %(hogql_val_23)s AS cohort_period- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_16)s)), sumStateIf(1, equals(events.event, %(hogql_val_17)s))) AS cohort_metrics, %(hogql_val_18)s AS cohort_period- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_19)s, 6, %(hogql_val_20)s)), less(events.timestamp, toDateTime64(%(hogql_val_21)s, 6, %(hogql_val_22)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_complex_nested_aggregation_patterns'''@@ -66,27 +43,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_complex_nested_aggregation_patterns[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(comprehensive_metrics, 1)), countMerge(tupleElement(comprehensive_metrics, 2)), sumMerge(tupleElement(comprehensive_metrics, 3)), avgMerge(tupleElement(comprehensive_metrics, 4))) AS comprehensive_metrics, source AS source- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_0)s)), sumStateIf(1, equals(events.event, %(hogql_val_1)s)), avgStateIf(1, equals(events.event, %(hogql_val_2)s))) AS comprehensive_metrics, if(notEquals(toJSONString(events.properties.^campaign_source), '{}'), toJSONString(events.properties.^campaign_source), if(isNull(events.properties.campaign_source), NULL, if(startsWith(dynamicType(events.properties.campaign_source), 'DateTime'), replaceOne(toString(events.properties.campaign_source), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.campaign_source), 'Array'), startsWith(dynamicType(events.properties.campaign_source), 'Map'), startsWith(dynamicType(events.properties.campaign_source), 'Tuple')), toJSONString(events.properties.campaign_source), toString(events.properties.campaign_source))))) AS source- FROM events_json AS events- WHERE and(equals(events.team_id, 420), ifNull(equals(if(notEquals(toJSONString(events.properties.^campaign_source), '{}'), toJSONString(events.properties.^campaign_source), if(isNull(events.properties.campaign_source), NULL, if(startsWith(dynamicType(events.properties.campaign_source), 'DateTime'), replaceOne(toString(events.properties.campaign_source), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.campaign_source), 'Array'), startsWith(dynamicType(events.properties.campaign_source), 'Map'), startsWith(dynamicType(events.properties.campaign_source), 'Tuple')), toJSONString(events.properties.campaign_source), toString(events.properties.campaign_source))))), %(hogql_val_3)s), 0))- GROUP BY source)- GROUP BY source- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(comprehensive_metrics, 1)), countMerge(tupleElement(comprehensive_metrics, 2)), sumMerge(tupleElement(comprehensive_metrics, 3)), avgMerge(tupleElement(comprehensive_metrics, 4))) AS comprehensive_metrics, source AS source- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_4)s)), sumStateIf(1, equals(events.event, %(hogql_val_5)s)), avgStateIf(1, equals(events.event, %(hogql_val_6)s))) AS comprehensive_metrics, if(notEquals(toJSONString(events.properties.^campaign_source), '{}'), toJSONString(events.properties.^campaign_source), if(isNull(events.properties.campaign_source), NULL, if(startsWith(dynamicType(events.properties.campaign_source), 'DateTime'), replaceOne(toString(events.properties.campaign_source), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.campaign_source), 'Array'), startsWith(dynamicType(events.properties.campaign_source), 'Map'), startsWith(dynamicType(events.properties.campaign_source), 'Tuple')), toJSONString(events.properties.campaign_source), toString(events.properties.campaign_source))))) AS source- FROM events_json AS events- WHERE and(equals(events.team_id, 420), ifNull(equals(if(notEquals(toJSONString(events.properties.^campaign_source), '{}'), toJSONString(events.properties.^campaign_source), if(isNull(events.properties.campaign_source), NULL, if(startsWith(dynamicType(events.properties.campaign_source), 'DateTime'), replaceOne(toString(events.properties.campaign_source), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.campaign_source), 'Array'), startsWith(dynamicType(events.properties.campaign_source), 'Map'), startsWith(dynamicType(events.properties.campaign_source), 'Tuple')), toJSONString(events.properties.campaign_source), toString(events.properties.campaign_source))))), %(hogql_val_7)s), 0))- GROUP BY source)- GROUP BY source- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_funnel_analysis_segments'''@@ -104,23 +60,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_funnel_analysis_segments[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(funnel_metrics, 1)), countMerge(tupleElement(funnel_metrics, 2)), countMerge(tupleElement(funnel_metrics, 3))) AS funnel_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_0)s)), countStateIf(equals(events.event, %(hogql_val_1)s))) AS funnel_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), ifNull(equals(if(notEquals(toJSONString(events.properties.^device_type), '{}'), toJSONString(events.properties.^device_type), if(isNull(events.properties.device_type), NULL, if(startsWith(dynamicType(events.properties.device_type), 'DateTime'), replaceOne(toString(events.properties.device_type), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.device_type), 'Array'), startsWith(dynamicType(events.properties.device_type), 'Map'), startsWith(dynamicType(events.properties.device_type), 'Tuple')), toJSONString(events.properties.device_type), toString(events.properties.device_type))))), %(hogql_val_2)s), 0)))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(funnel_metrics, 1)), countMerge(tupleElement(funnel_metrics, 2)), countMerge(tupleElement(funnel_metrics, 3))) AS funnel_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_3)s)), countStateIf(equals(events.event, %(hogql_val_4)s))) AS funnel_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), ifNull(equals(if(notEquals(toJSONString(events.properties.^device_type), '{}'), toJSONString(events.properties.^device_type), if(isNull(events.properties.device_type), NULL, if(startsWith(dynamicType(events.properties.device_type), 'DateTime'), replaceOne(toString(events.properties.device_type), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.device_type), 'Array'), startsWith(dynamicType(events.properties.device_type), 'Map'), startsWith(dynamicType(events.properties.device_type), 'Tuple')), toJSONString(events.properties.device_type), toString(events.properties.device_type))))), %(hogql_val_5)s), 0)))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_mixed_transformation_stages_with_tuples'''@@ -142,27 +81,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_mixed_transformation_stages_with_tuples[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(activity_metrics, 1)), avgMerge(tupleElement(activity_metrics, 2))) AS activity_metrics, date AS date- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(1)) AS activity_metrics, toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS date- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(toDate(toTimeZone(events.timestamp, %(hogql_val_1)s)), %(hogql_val_2)s))- GROUP BY date)- GROUP BY date- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(activity_metrics, 1)), avgMerge(tupleElement(activity_metrics, 2))) AS activity_metrics, date AS date- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(1)) AS activity_metrics, toDate(toTimeZone(events.timestamp, %(hogql_val_3)s)) AS date- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s)))- GROUP BY date)- GROUP BY date- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_multiple_time_periods_with_conditional_aggregations'''@@ -180,23 +98,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_multiple_time_periods_with_conditional_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(metrics, 1)), countMerge(tupleElement(metrics, 2)), sumMerge(tupleElement(metrics, 3))) AS metrics- FROM (- SELECT tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_0)s)), countStateIf(equals(events.event, %(hogql_val_1)s)), sumStateIf(1, 1)) AS metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s)), less(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(metrics, 1)), countMerge(tupleElement(metrics, 2)), sumMerge(tupleElement(metrics, 3))) AS metrics- FROM (- SELECT tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_6)s)), countStateIf(equals(events.event, %(hogql_val_7)s)), sumStateIf(1, 1)) AS metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_8)s, 6, %(hogql_val_9)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_regular_and_state_aggregations_mixed'''@@ -214,23 +115,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_regular_and_state_aggregations_mixed[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(metrics, 1)), countMerge(tupleElement(metrics, 2)), sumMerge(tupleElement(metrics, 3))) AS metrics, %(hogql_val_4)s AS source_type- FROM (- SELECT tuple(uniqState(events.distinct_id), countState(), sumStateIf(1, equals(events.event, %(hogql_val_0)s))) AS metrics, %(hogql_val_1)s AS source_type- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(metrics, 1)), countMerge(tupleElement(metrics, 2)), sumMerge(tupleElement(metrics, 3))) AS metrics, %(hogql_val_9)s AS source_type- FROM (- SELECT tuple(uniqState(events.distinct_id), countState(), sumStateIf(1, equals(events.event, %(hogql_val_5)s))) AS metrics, %(hogql_val_6)s AS source_type- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, toDateTime64(%(hogql_val_7)s, 6, %(hogql_val_8)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_three_data_sources_with_mixed_tuples'''@@ -260,35 +144,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_three_data_sources_with_mixed_tuples[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(value_metrics, 1)), avgMerge(tupleElement(value_metrics, 2))) AS value_metrics, host AS host- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(1)) AS value_metrics, events.properties.`$host` AS host- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- GROUP BY host)- GROUP BY host- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(value_metrics, 1)), avgMerge(tupleElement(value_metrics, 2))) AS value_metrics, host AS host- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(1)) AS value_metrics, events.properties.`$host` AS host- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s)), less(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s)))- GROUP BY host)- GROUP BY host- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(value_metrics, 1)), avgMerge(tupleElement(value_metrics, 2))) AS value_metrics, host AS host- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(1)) AS value_metrics, events.properties.`$host` AS host- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_6)s, 6, %(hogql_val_7)s)))- GROUP BY host)- GROUP BY host- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_two_different_state_queries_into_one_merge_query'''@@ -306,23 +161,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_two_different_state_queries_into_one_merge_query[new_events_schema]- '''-- SELECT countMerge(total_pageviews) AS total_pageviews- FROM (- SELECT countState() AS total_pageviews- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, minus(now64(6, %(hogql_val_0)s), toIntervalDay(1)))))- LIMIT 50000 UNION ALL- SELECT countMerge(total_pageviews) AS total_pageviews- FROM (- SELECT countState() AS total_pageviews- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, minus(now64(6, %(hogql_val_1)s), toIntervalDay(1)))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_combine_web_analytics_historical_and_realtime_data'''@@ -344,27 +182,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_combine_web_analytics_historical_and_realtime_data[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(daily_metrics, 1)), countMerge(tupleElement(daily_metrics, 2)), sumMerge(tupleElement(daily_metrics, 3))) AS daily_metrics, date AS date- FROM (- SELECT tuple(uniqState(events.distinct_id), countState(), sumStateIf(1, equals(events.event, %(hogql_val_0)s))) AS daily_metrics, toDate(toTimeZone(events.timestamp, %(hogql_val_1)s)) AS date- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(toDate(toTimeZone(events.timestamp, %(hogql_val_2)s)), %(hogql_val_3)s))- GROUP BY date)- GROUP BY date- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(daily_metrics, 1)), countMerge(tupleElement(daily_metrics, 2)), sumMerge(tupleElement(daily_metrics, 3))) AS daily_metrics, date AS date- FROM (- SELECT tuple(uniqState(events.distinct_id), countState(), sumStateIf(1, equals(events.event, %(hogql_val_4)s))) AS daily_metrics, toDate(toTimeZone(events.timestamp, %(hogql_val_5)s)) AS date- FROM events_json AS events- WHERE and(equals(events.team_id, 420), equals(toDate(toTimeZone(events.timestamp, %(hogql_val_6)s)), %(hogql_val_7)s))- GROUP BY date)- GROUP BY date- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_complex_tuple_union_all_with_grouping'''@@ -386,27 +203,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_complex_tuple_union_all_with_grouping[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(stats_tuple, 1)), countMerge(tupleElement(stats_tuple, 2)), sumMerge(tupleElement(stats_tuple, 3))) AS stats_tuple, date_key AS date_key- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(1), sumState(1)) AS stats_tuple, toDate(toTimeZone(events.timestamp, %(hogql_val_0)s)) AS date_key- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(toDate(toTimeZone(events.timestamp, %(hogql_val_1)s)), %(hogql_val_2)s))- GROUP BY date_key)- GROUP BY date_key- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(stats_tuple, 1)), countMerge(tupleElement(stats_tuple, 2)), sumMerge(tupleElement(stats_tuple, 3))) AS stats_tuple, date_key AS date_key- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(1), sumState(1)) AS stats_tuple, toDate(toTimeZone(events.timestamp, %(hogql_val_3)s)) AS date_key- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(toDate(toTimeZone(events.timestamp, %(hogql_val_4)s)), %(hogql_val_5)s))- GROUP BY date_key)- GROUP BY date_key- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_filtered_aggregation'''@@ -418,17 +214,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_filtered_aggregation[new_events_schema]- '''-- SELECT uniqMerge(unique_users) AS unique_users, countMerge(total_events) AS total_events- FROM (- SELECT uniqState(events.distinct_id) AS unique_users, countState() AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_0)s)))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_merge_wraps_works_with_more_complex_queries'''@@ -445,22 +230,6 @@LIMIT 10'''# ----# name: TestStateTransforms.test_merge_wraps_works_with_more_complex_queries[new_events_schema]- '''-- SELECT uniqMerge(unique_users) AS unique_users, countMerge(total_events) AS total_events, host AS host- FROM (- SELECT uniqState(events.distinct_id) AS unique_users, countState() AS total_events, events.properties.`$host` AS host- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- GROUP BY host- ORDER BY total_events DESC- LIMIT 10)- GROUP BY host- ORDER BY total_events DESC- LIMIT 10- '''-# ---# name: TestStateTransforms.test_multi_level_tuple_union_all_transformation'''@@ -478,23 +247,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_multi_level_tuple_union_all_transformation[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(session_metrics, 1)), avgMerge(tupleElement(session_metrics, 2))) AS session_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^duration), '{}'), toJSONString(events.properties.^duration), if(isNull(events.properties.duration), NULL, if(startsWith(dynamicType(events.properties.duration), 'DateTime'), replaceOne(toString(events.properties.duration), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.duration), 'Array'), startsWith(dynamicType(events.properties.duration), 'Map'), startsWith(dynamicType(events.properties.duration), 'Tuple')), toJSONString(events.properties.duration), toString(events.properties.duration))))), %(hogql_val_0)s))) AS session_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(user_metrics, 1)), countMerge(tupleElement(user_metrics, 2))) AS user_metrics, tuple(sumMerge(tupleElement(session_metrics, 1)), avgMerge(tupleElement(session_metrics, 2))) AS session_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_metrics, tuple(sumState(1), avgState(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^duration), '{}'), toJSONString(events.properties.^duration), if(isNull(events.properties.duration), NULL, if(startsWith(dynamicType(events.properties.duration), 'DateTime'), replaceOne(toString(events.properties.duration), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.duration), 'Array'), startsWith(dynamicType(events.properties.duration), 'Map'), startsWith(dynamicType(events.properties.duration), 'Tuple')), toJSONString(events.properties.duration), toString(events.properties.duration))))), %(hogql_val_3)s))) AS session_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_multiple_tuples_with_state_aggregations'''@@ -506,17 +258,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_multiple_tuples_with_state_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_stats, 1)), countMerge(tupleElement(user_stats, 2))) AS user_stats, tuple(sumMerge(tupleElement(metric_stats, 1)), avgMerge(tupleElement(metric_stats, 2))) AS metric_stats- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_stats, tuple(sumState(1), avgState(1)) AS metric_stats- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_nested_aggregations_in_subquery'''@@ -531,20 +272,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_nested_aggregations_in_subquery[new_events_schema]- '''-- SELECT sumMerge(total_filtered_count) AS total_filtered_count- FROM (- SELECT sumState(filtered_count) AS total_filtered_count- FROM (- SELECT countIf(equals(events.event, %(hogql_val_0)s)) AS filtered_count- FROM events_json AS events- WHERE equals(events.team_id, 420)- GROUP BY events.distinct_id))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_nested_functions_aggregations_and_conversions'''@@ -558,19 +285,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_nested_functions_aggregations_and_conversions[new_events_schema]- '''-- SELECT host AS host, uniqMerge(unique_users) AS unique_users, sumMerge(click_count) AS click_count, avgMerge(avg_duration) AS avg_duration- FROM (- SELECT events.properties.`$host` AS host, uniqState(events.distinct_id) AS unique_users, sumStateIf(1, equals(events.event, %(hogql_val_0)s)) AS click_count, avgState(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^session_duration), '{}'), toJSONString(events.properties.^session_duration), if(isNull(events.properties.session_duration), NULL, if(startsWith(dynamicType(events.properties.session_duration), 'DateTime'), replaceOne(toString(events.properties.session_duration), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.session_duration), 'Array'), startsWith(dynamicType(events.properties.session_duration), 'Map'), startsWith(dynamicType(events.properties.session_duration), 'Tuple')), toJSONString(events.properties.session_duration), toString(events.properties.session_duration))))), %(hogql_val_1)s)) AS avg_duration- FROM events_json AS events- WHERE equals(events.team_id, 420)- GROUP BY host)- GROUP BY host- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_nested_subquery_with_tuple_union_all'''@@ -587,22 +301,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_nested_subquery_with_tuple_union_all[new_events_schema]- '''-- SELECT sumMerge(final_users) AS final_users, avgMerge(final_avg_duration) AS final_avg_duration- FROM (- SELECT sumState(combined_stats.total_users) AS final_users, avgState(combined_stats.avg_duration) AS final_avg_duration- FROM (- SELECT tuple(uniqState(events.distinct_id), avgState(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^session_duration), '{}'), toJSONString(events.properties.^session_duration), if(isNull(events.properties.session_duration), NULL, if(startsWith(dynamicType(events.properties.session_duration), 'DateTime'), replaceOne(toString(events.properties.session_duration), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.session_duration), 'Array'), startsWith(dynamicType(events.properties.session_duration), 'Map'), startsWith(dynamicType(events.properties.session_duration), 'Tuple')), toJSONString(events.properties.session_duration), toString(events.properties.session_duration))))), %(hogql_val_0)s))) AS user_duration_tuple, tupleElement(user_duration_tuple, 1) AS total_users, tupleElement(user_duration_tuple, 2) AS avg_duration- FROM events_json AS events- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_1)s), less(events.timestamp, toDateTime64(%(hogql_val_2)s, 6, %(hogql_val_3)s))) UNION ALL- SELECT tuple(uniqState(events.distinct_id), avgState(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^session_duration), '{}'), toJSONString(events.properties.^session_duration), if(isNull(events.properties.session_duration), NULL, if(startsWith(dynamicType(events.properties.session_duration), 'DateTime'), replaceOne(toString(events.properties.session_duration), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.session_duration), 'Array'), startsWith(dynamicType(events.properties.session_duration), 'Map'), startsWith(dynamicType(events.properties.session_duration), 'Tuple')), toJSONString(events.properties.session_duration), toString(events.properties.session_duration))))), %(hogql_val_4)s))) AS user_duration_tuple, tupleElement(user_duration_tuple, 1) AS total_users, tupleElement(user_duration_tuple, 2) AS avg_duration- FROM events_json AS events- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_5)s), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_6)s, 6, %(hogql_val_7)s)))) AS combined_stats)- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_preserve_group_by'''@@ -613,16 +311,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_preserve_group_by[new_events_schema]- '''-- SELECT events.properties.`$pathname` AS pathname, uniqState(events.distinct_id) AS unique_users, countState() AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- GROUP BY pathname- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_preserve_query_without_aggregations'''@@ -632,15 +320,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_preserve_query_without_aggregations[new_events_schema]- '''-- SELECT events.distinct_id AS distinct_id, events.properties.`$pathname` AS pathname- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_query_similar_to_web_overview_query_transformation_sql'''@@ -655,20 +334,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_query_similar_to_web_overview_query_transformation_sql[new_events_schema]- '''-- SELECT sumMerge(total_pageviews) AS total_pageviews, uniqMerge(unique_users) AS unique_users- FROM (- SELECT sumState(pageview_count) AS total_pageviews, uniqState(user_id) AS unique_users- FROM (- SELECT events.distinct_id AS user_id, countIf(equals(events.event, %(hogql_val_0)s)) AS pageview_count- FROM events_json AS events- WHERE equals(events.team_id, 420)- GROUP BY events.distinct_id))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_query_with_as_constants'''@@ -680,17 +345,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_query_with_as_constants[new_events_schema]- '''-- SELECT uniqMerge(unique_users) AS unique_users, NULL AS previous_unique_users, countMerge(total_events) AS total_events, 123 AS constant_value- FROM (- SELECT uniqState(events.distinct_id) AS unique_users, NULL AS previous_unique_users, countState() AS total_events, 123 AS constant_value- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_three_way_mixed_aggregation_stages'''@@ -714,29 +368,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_three_way_mixed_aggregation_stages[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(pageview_metrics, 1)), countMerge(tupleElement(pageview_metrics, 2))) AS pageview_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_0)s))) AS pageview_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(pageview_metrics, 1)), countMerge(tupleElement(pageview_metrics, 2))) AS pageview_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_3)s))) AS pageview_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s)), less(events.timestamp, toDateTime64(%(hogql_val_6)s, 6, %(hogql_val_7)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(pageview_metrics, 1)), countMerge(tupleElement(pageview_metrics, 2))) AS pageview_metrics- FROM (- SELECT tuple(uniqState(events.distinct_id), countStateIf(equals(events.event, %(hogql_val_8)s))) AS pageview_metrics- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_9)s, 6, %(hogql_val_10)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_transform_nested_expressions'''@@ -746,15 +377,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_transform_nested_expressions[new_events_schema]- '''-- SELECT uniqState(events.distinct_id) AS unique_users, countState(if(equals(events.event, %(hogql_val_0)s), 1, 0)) AS pageview_count- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s)))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_transform_simple_query_to_state_aggregations'''@@ -764,15 +386,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_transform_simple_query_to_state_aggregations[new_events_schema]- '''-- SELECT uniqState(events.distinct_id) AS unique_users, countState() AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_transformation_from_regular_to_state_then_merge_with_tuples'''@@ -784,17 +397,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_transformation_from_regular_to_state_then_merge_with_tuples[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_stats, 1)), countMerge(tupleElement(user_stats, 2))) AS user_stats, tuple(sumMerge(tupleElement(metric_stats, 1)), avgMerge(tupleElement(metric_stats, 2))) AS metric_stats- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_stats, tuple(sumState(1), avgState(1)) AS metric_stats- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_in_subquery_remains_unchanged'''@@ -808,19 +410,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_in_subquery_remains_unchanged[new_events_schema]- '''-- SELECT sumMerge(aggregated_total) AS aggregated_total- FROM (- SELECT sumState(filtered_metrics.total_count) AS aggregated_total- FROM (- SELECT tuple(uniq(events.distinct_id), count()) AS user_metrics, sum(1) AS total_count- FROM events_json AS events- WHERE equals(events.team_id, 420)) AS filtered_metrics)- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_union_all_with_different_conditions'''@@ -838,23 +427,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_union_all_with_different_conditions[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(pageview_stats, 1)), countMerge(tupleElement(pageview_stats, 2))) AS pageview_stats, tuple(uniqMerge(tupleElement(click_stats, 1)), countMerge(tupleElement(click_stats, 2))) AS click_stats- FROM (- SELECT tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_0)s)), countStateIf(equals(events.event, %(hogql_val_1)s))) AS pageview_stats, tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_2)s)), countStateIf(equals(events.event, %(hogql_val_3)s))) AS click_stats- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_4)s, 6, %(hogql_val_5)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_6)s, 6, %(hogql_val_7)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(pageview_stats, 1)), countMerge(tupleElement(pageview_stats, 2))) AS pageview_stats, tuple(uniqMerge(tupleElement(click_stats, 1)), countMerge(tupleElement(click_stats, 2))) AS click_stats- FROM (- SELECT tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_8)s)), countStateIf(equals(events.event, %(hogql_val_9)s))) AS pageview_stats, tuple(uniqStateIf(events.distinct_id, equals(events.event, %(hogql_val_10)s)), countStateIf(equals(events.event, %(hogql_val_11)s))) AS click_stats- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_12)s, 6, %(hogql_val_13)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_14)s, 6, %(hogql_val_15)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_with_conditional_aggregations'''@@ -866,17 +438,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_with_conditional_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(conditional_stats, 1)), countMerge(tupleElement(conditional_stats, 2)), sumMerge(tupleElement(conditional_stats, 3))) AS conditional_stats- FROM (- SELECT tuple(uniqStateIf(events.distinct_id, 1), countStateIf(1), sumStateIf(1, 1)) AS conditional_stats- FROM events_json AS events- WHERE equals(events.team_id, 420))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_with_constants_and_state_aggregations'''@@ -888,17 +449,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_with_constants_and_state_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(mixed_tuple, 1)), tupleElement(mixed_tuple, 2), countMerge(tupleElement(mixed_tuple, 3)), tupleElement(mixed_tuple, 4), tupleElement(mixed_tuple, 5)) AS mixed_tuple- FROM (- SELECT tuple(uniqState(events.distinct_id), NULL, countState(), %(hogql_val_0)s, 42) AS mixed_tuple- FROM events_json AS events- WHERE equals(events.team_id, 420))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_with_mixed_aggregations_and_non_aggregations'''@@ -910,17 +460,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_with_mixed_aggregations_and_non_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(mixed_stats, 1)), tupleElement(mixed_stats, 2), countMerge(tupleElement(mixed_stats, 3))) AS mixed_stats, sumMerge(total_sum) AS total_sum- FROM (- SELECT tuple(uniqState(events.distinct_id), %(hogql_val_0)s, countState()) AS mixed_stats, sumState(1) AS total_sum- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_tuple_with_state_aggregations'''@@ -934,19 +473,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_tuple_with_state_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_stats, 1)), countMerge(tupleElement(user_stats, 2))) AS user_stats, host AS host- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_stats, events.properties.`$host` AS host- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s)))- GROUP BY host)- GROUP BY host- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_union_all_state_queries_into_one_merge_query'''@@ -964,23 +490,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_union_all_state_queries_into_one_merge_query[new_events_schema]- '''-- SELECT countMerge(total_pageviews) AS total_pageviews- FROM (- SELECT countState() AS total_pageviews- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, minus(now64(6, %(hogql_val_0)s), toIntervalDay(1)))))- LIMIT 50000 UNION ALL- SELECT countMerge(total_pageviews) AS total_pageviews- FROM (- SELECT countState() AS total_pageviews- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, minus(now64(6, %(hogql_val_1)s), toIntervalDay(1)))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_union_all_tuples_with_state_aggregations'''@@ -998,23 +507,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_union_all_tuples_with_state_aggregations[new_events_schema]- '''-- SELECT tuple(uniqMerge(tupleElement(user_stats, 1)), countMerge(tupleElement(user_stats, 2))) AS user_stats, tuple(sumMerge(tupleElement(metric_stats, 1)), avgMerge(tupleElement(metric_stats, 2))) AS metric_stats, %(hogql_val_3)s AS data_source- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_stats, tuple(sumState(1), avgState(1)) AS metric_stats, %(hogql_val_0)s AS data_source- FROM events_json AS events- WHERE and(equals(events.team_id, 420), less(events.timestamp, toDateTime64(%(hogql_val_1)s, 6, %(hogql_val_2)s))))- LIMIT 50000 UNION ALL- SELECT tuple(uniqMerge(tupleElement(user_stats, 1)), countMerge(tupleElement(user_stats, 2))) AS user_stats, tuple(sumMerge(tupleElement(metric_stats, 1)), avgMerge(tupleElement(metric_stats, 2))) AS metric_stats, %(hogql_val_7)s AS data_source- FROM (- SELECT tuple(uniqState(events.distinct_id), countState()) AS user_stats, tuple(sumState(1), avgState(1)) AS metric_stats, %(hogql_val_4)s AS data_source- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_wrap_state_query_in_merge_query'''@@ -1026,17 +518,6 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_wrap_state_query_in_merge_query[new_events_schema]- '''-- SELECT uniqMerge(unique_users) AS unique_users, countMerge(total_events) AS total_events- FROM (- SELECT uniqState(events.distinct_id) AS unique_users, countState() AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 420), greaterOrEquals(events.timestamp, toDateTime64(%(hogql_val_0)s, 6, %(hogql_val_1)s))))- LIMIT 50000- '''-# ---# name: TestStateTransforms.test_wrapper_query_aggregation_with_groupby'''@@ -1050,16 +531,3 @@LIMIT 50000'''# ----# name: TestStateTransforms.test_wrapper_query_aggregation_with_groupby[new_events_schema]- '''-- SELECT host AS host, countMerge(total_count) AS total_count, countMerge(click_count) AS click_count- FROM (- SELECT events.properties.`$host` AS host, countState() AS total_count, countStateIf(equals(events.event, %(hogql_val_0)s)) AS click_count- FROM events_json AS events- WHERE equals(events.team_id, 420)- GROUP BY host)- GROUP BY host- LIMIT 50000- '''-# ---diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_event_taxonomy_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_event_taxonomy_query_runner.ambrindex 4433c87d0a00..8820b809780e 100644--- a/posthog/hogql_queries/ai/test/__snapshots__/test_event_taxonomy_query_runner.ambr+++ b/posthog/hogql_queries/ai/test/__snapshots__/test_event_taxonomy_query_runner.ambr@@ -40,49 +40,6 @@use_hive_partitioning=0'''# ----# name: TestEventTaxonomyQueryRunner.test_event_taxonomy_query_runner[new_events_schema]- '''- SELECT key AS key,- arrayMap(item -> item.3, arraySlice(reverse(arraySort(item -> tuple(item.1, item.2, item.3), groupArray(tuple(value_count, latest_seen, value)))), 1, 5)) AS- values,- count(DISTINCT value) AS total_count- FROM- (SELECT key,- value,- count() AS value_count,- max(timestamp) AS latest_seen- FROM- (SELECT JSONExtractKeysAndValues(concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), 'String') AS kv,- toTimeZone(events.timestamp, 'UTC') AS timestamp- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, minus(now64(6, 'UTC'), toIntervalDay(30))), equals(events.event, 'event1'))- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC- LIMIT 100) ARRAY- JOIN (kv).1 AS key,- (kv).2 AS value- WHERE and(not(match(key, '(\\$set|\\$time|\\$set_once|\\$sent_at|distinct_id|\\$ip|\\$feature\\/|\\$feature_enrollment\\/|\\$feature_interaction\\/|\\$product_tour|__|survey_dismiss|survey_responded|phjs|partial_filter_chosen|changed_action|window-id|changed_event|partial_filter)')), isNotNull(value), ifNull(notEquals(value, ''), 1))- GROUP BY key,- value)- GROUP BY key- ORDER BY total_count DESC,- key ASC- LIMIT 501- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestEventTaxonomyQueryRunner.test_property_taxonomy_handles_numeric_property_values'''SELECT key AS key,@@ -122,45 +79,6 @@use_hive_partitioning=0'''# ----# name: TestEventTaxonomyQueryRunner.test_property_taxonomy_handles_numeric_property_values[new_events_schema]- '''- SELECT key AS key,- arrayMap(item -> item.3, arraySlice(reverse(arraySort(item -> tuple(item.1, item.2, item.3), groupArray(tuple(value_count, latest_seen, value)))), 1, 5)) AS- values,- count(DISTINCT value) AS total_count- FROM- (SELECT key,- value,- count() AS value_count,- max(timestamp) AS latest_seen- FROM- (SELECT [tuple('zero_duration_recording_count_in_period', JSONExtractString(ifNull(if(notEquals(toJSONString(events.properties.^zero_duration_recording_count_in_period), '{}'), toJSONString(events.properties.^zero_duration_recording_count_in_period), if(isNull(events.properties.zero_duration_recording_count_in_period), NULL, if(startsWith(dynamicType(events.properties.zero_duration_recording_count_in_period), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.zero_duration_recording_count_in_period), ' ', 'T')), ''), '"'), toJSONString(events.properties.zero_duration_recording_count_in_period)))), '')))] AS kv,- toTimeZone(events.timestamp, 'UTC') AS timestamp- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, minus(now64(6, 'UTC'), toIntervalDay(30))), equals(events.event, 'organization usage report'), notEquals(JSONExtractString(ifNull(if(notEquals(toJSONString(events.properties.^zero_duration_recording_count_in_period), '{}'), toJSONString(events.properties.^zero_duration_recording_count_in_period), if(isNull(events.properties.zero_duration_recording_count_in_period), NULL, if(startsWith(dynamicType(events.properties.zero_duration_recording_count_in_period), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(events.properties.zero_duration_recording_count_in_period), ' ', 'T')), ''), '"'), toJSONString(events.properties.zero_duration_recording_count_in_period)))), '')), ''))) ARRAY- JOIN (kv).1 AS key,- (kv).2 AS value- WHERE and(isNotNull(value), ifNull(notEquals(value, ''), 1))- GROUP BY key,- value)- GROUP BY key- ORDER BY total_count DESC,- key ASC- LIMIT 501- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestEventTaxonomyQueryRunner.test_retrieves_action_properties'''SELECT key AS key,@@ -202,46 +120,3 @@use_hive_partitioning=0'''# ----# name: TestEventTaxonomyQueryRunner.test_retrieves_action_properties[new_events_schema]- '''- SELECT key AS key,- arrayMap(item -> item.3, arraySlice(reverse(arraySort(item -> tuple(item.1, item.2, item.3), groupArray(tuple(value_count, latest_seen, value)))), 1, 5)) AS- values,- count(DISTINCT value) AS total_count- FROM- (SELECT key,- value,- count() AS value_count,- max(timestamp) AS latest_seen- FROM- (SELECT JSONExtractKeysAndValues(concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}'), 'String') AS kv,- toTimeZone(events.timestamp, 'UTC') AS timestamp- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, minus(now64(6, 'UTC'), toIntervalDay(30))), equals(events.event, '$pageview'))- ORDER BY toTimeZone(events.timestamp, 'UTC') DESC- LIMIT 100) ARRAY- JOIN (kv).1 AS key,- (kv).2 AS value- WHERE and(not(match(key, '(\\$set|\\$time|\\$set_once|\\$sent_at|distinct_id|\\$ip|\\$feature\\/|\\$feature_enrollment\\/|\\$feature_interaction\\/|\\$product_tour|__|survey_dismiss|survey_responded|phjs|partial_filter_chosen|changed_action|window-id|changed_event|partial_filter)')), isNotNull(value), ifNull(notEquals(value, ''), 1))- GROUP BY key,- value)- GROUP BY key- ORDER BY total_count DESC,- key ASC- LIMIT 501- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_suggested_questions_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_suggested_questions_query_runner.ambrindex e45fec59743a..fd5132ddbcda 100644--- a/posthog/hogql_queries/ai/test/__snapshots__/test_suggested_questions_query_runner.ambr+++ b/posthog/hogql_queries/ai/test/__snapshots__/test_suggested_questions_query_runner.ambr@@ -22,26 +22,3 @@use_hive_partitioning=0'''# ----# name: TestSuggestedQuestionsQueryRunner.test_suggested_questions_hit_openai[new_events_schema]- '''- SELECT events.event AS event,- count() AS count- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, minus(now64(6, 'UTC'), toIntervalDay(30))), notIn(events.event, ['$pageleave', '$autocapture', '$$heatmap', '$copy_autocapture', '$set', '$opt_in', '$feature_flag_called', '$feature_view', '$feature_interaction', '$element_viewed', '$capture_metrics', '$create_alias', '$merge_dangerously', '$groupidentify', 'mcp_tool_call', 'mcp_tools_list', 'mcp_initialize', 'mcp_resources_list', 'mcp_resource_read', 'mcp_prompts_list', 'mcp_prompt_get', 'mcp_custom', 'posthog_identify', 'mcp init', 'mcp_mcpcat:identify', 'mcp_posthog:identify', 'mcp_tool_called', 'mcp tool call', 'mcp tool response', '$snapshot']))- GROUP BY events.event- ORDER BY count DESC, events.event ASC- LIMIT 501- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_team_taxonomy_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_team_taxonomy_query_runner.ambrindex acdcd3248cca..8f0eb8b08e1d 100644--- a/posthog/hogql_queries/ai/test/__snapshots__/test_team_taxonomy_query_runner.ambr+++ b/posthog/hogql_queries/ai/test/__snapshots__/test_team_taxonomy_query_runner.ambr@@ -22,26 +22,3 @@use_hive_partitioning=0'''# ----# name: TestTeamTaxonomyQueryRunner.test_taxonomy_query_runner[new_events_schema]- '''- SELECT events.event AS event,- count() AS count- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, minus(now64(6, 'UTC'), toIntervalDay(30))), notIn(events.event, ['$pageleave', '$autocapture', '$$heatmap', '$copy_autocapture', '$set', '$opt_in', '$feature_flag_called', '$feature_view', '$feature_interaction', '$element_viewed', '$capture_metrics', '$create_alias', '$merge_dangerously', '$groupidentify', 'mcp_tool_call', 'mcp_tools_list', 'mcp_initialize', 'mcp_resources_list', 'mcp_resource_read', 'mcp_prompts_list', 'mcp_prompt_get', 'mcp_custom', 'posthog_identify', 'mcp init', 'mcp_mcpcat:identify', 'mcp_posthog:identify', 'mcp_tool_called', 'mcp tool call', 'mcp tool response', '$snapshot']))- GROUP BY events.event- ORDER BY count DESC, events.event ASC- LIMIT 501- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_trace_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_trace_query_runner.ambrindex 30e6e474982b..5feb8ab911dd 100644--- a/posthog/hogql_queries/ai/test/__snapshots__/test_trace_query_runner.ambr+++ b/posthog/hogql_queries/ai/test/__snapshots__/test_trace_query_runner.ambr@@ -235,67 +235,6 @@use_hive_partitioning=0'''# ----# name: TestTraceQueryRunner.test_event_property_filters[new_events_schema]- '''- SELECT deduped.trace_id AS id,- any(deduped.session_id) AS ai_session_id,- min(deduped.timestamp) AS first_timestamp,- max(deduped.timestamp) AS last_timestamp,- ifNull(nullIf(argMinIf(deduped.distinct_id, deduped.timestamp, equals(deduped.event, '$ai_trace')), ''), argMin(deduped.distinct_id, deduped.timestamp)) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(deduped.latency, 0), 0), notEquals(deduped.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(deduped.latency, 0), 0), equals(deduped.event, '$ai_generation'))), 0)), sumIf(deduped.latency, and(equals(deduped.event, '$ai_generation'), ifNull(greater(deduped.latency, 0), 0))), sumIf(deduped.latency, or(isNull(deduped.parent_id), ifNull(equals(deduped.parent_id, deduped.trace_id), isNull(deduped.parent_id)- and isNull(deduped.trace_id))))), 2) AS total_latency,- nullIf(sumIf(deduped.input_tokens, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 0) AS input_tokens,- nullIf(sumIf(deduped.output_tokens, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 0) AS output_tokens,- nullIf(round(sumIf(deduped.input_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS input_cost,- nullIf(round(sumIf(deduped.output_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS output_cost,- nullIf(round(sumIf(deduped.total_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(deduped.uuid, deduped.event, deduped.timestamp, deduped.properties, deduped.input, deduped.output, deduped.output_choices, deduped.input_state, deduped.output_state, deduped.tools), notEquals(deduped.event, '$ai_trace')))) AS events,- argMinIf(deduped.input_state, deduped.timestamp, equals(deduped.event, '$ai_trace')) AS input_state,- argMinIf(deduped.output_state, deduped.timestamp, equals(deduped.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(nullIf(deduped.span_name, ''), nullIf(deduped.trace_name, '')), deduped.timestamp, equals(deduped.event, '$ai_trace')), argMin(ifNull(nullIf(deduped.span_name, ''), nullIf(deduped.trace_name, '')), deduped.timestamp)) AS trace_name- FROM- (SELECT __ai_events_fallback.uuid AS uuid,- __ai_events_fallback.event AS event,- toTimeZone(__ai_events_fallback.timestamp, 'UTC') AS timestamp,- __ai_events_fallback.distinct_id AS distinct_id,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(__ai_events_fallback.properties)))), ','), '}') AS properties,- __ai_events_fallback.properties.`$ai_trace_id` AS trace_id,- __ai_events_fallback.properties.`$ai_session_id` AS session_id,- __ai_events_fallback.properties.`$ai_parent_id` AS parent_id,- if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_span_name`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_span_name`), if(isNull(__ai_events_fallback.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_span_name`), toString(__ai_events_fallback.properties.`$ai_span_name`))))) AS span_name,- if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_trace_name`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_trace_name`), if(isNull(__ai_events_fallback.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_trace_name`), toString(__ai_events_fallback.properties.`$ai_trace_name`))))) AS trace_name,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_latency`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_latency`), if(isNull(__ai_events_fallback.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_latency`), toString(__ai_events_fallback.properties.`$ai_latency`))))), 'Float64'), 'Float64') AS latency,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_tokens`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_tokens`), if(isNull(__ai_events_fallback.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_input_tokens`), toString(__ai_events_fallback.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64') AS input_tokens,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_tokens`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_tokens`), if(isNull(__ai_events_fallback.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_output_tokens`), toString(__ai_events_fallback.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64') AS output_tokens,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_cost_usd`), if(isNull(__ai_events_fallback.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_input_cost_usd`), toString(__ai_events_fallback.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64') AS input_cost_usd,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_cost_usd`), if(isNull(__ai_events_fallback.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_output_cost_usd`), toString(__ai_events_fallback.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64') AS output_cost_usd,- accurateCastOrNull(accurateCastOrNull(__ai_events_fallback.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64') AS total_cost_usd,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input`), if(isNull(__ai_events_fallback.properties.`$ai_input`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_input`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_input`)))), '')) AS input,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output`), if(isNull(__ai_events_fallback.properties.`$ai_output`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output`)))), '')) AS output,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_choices`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_choices`), if(isNull(__ai_events_fallback.properties.`$ai_output_choices`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_choices`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output_choices`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output_choices`)))), '')) AS output_choices,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_state`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_state`), if(isNull(__ai_events_fallback.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_state`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_input_state`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_input_state`)))), '')) AS input_state,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_state`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_state`), if(isNull(__ai_events_fallback.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_state`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output_state`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output_state`)))), '')) AS output_state,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_tools`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_tools`), if(isNull(__ai_events_fallback.properties.`$ai_tools`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_tools`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_tools`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_tools`)))), '')) AS tools- FROM events_json AS __ai_events_fallback- WHERE and(equals(__ai_events_fallback.team_id, 99999), in(__ai_events_fallback.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(__ai_events_fallback.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(__ai_events_fallback.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC'))), equals(__ai_events_fallback.properties.`$ai_trace_id`, 'trace1'), ifNull(equals(if(notEquals(toJSONString(__ai_events_fallback.properties.^foo), '{}'), toJSONString(__ai_events_fallback.properties.^foo), if(isNull(__ai_events_fallback.properties.foo), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.foo), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.foo), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.foo), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.foo), 'Tuple')), toJSONString(__ai_events_fallback.properties.foo), toString(__ai_events_fallback.properties.foo))))), 'barz'), 0)))- LIMIT 1 BY __ai_events_fallback.uuid) AS deduped- GROUP BY deduped.trace_id- LIMIT 1 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTraceQueryRunner.test_person_property_filters'''SELECT deduped.trace_id AS id,@@ -526,81 +465,3 @@use_hive_partitioning=0'''# ----# name: TestTraceQueryRunner.test_person_property_filters[new_events_schema]- '''- SELECT deduped.trace_id AS id,- any(deduped.session_id) AS ai_session_id,- min(deduped.timestamp) AS first_timestamp,- max(deduped.timestamp) AS last_timestamp,- ifNull(nullIf(argMinIf(deduped.distinct_id, deduped.timestamp, equals(deduped.event, '$ai_trace')), ''), argMin(deduped.distinct_id, deduped.timestamp)) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(deduped.latency, 0), 0), notEquals(deduped.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(deduped.latency, 0), 0), equals(deduped.event, '$ai_generation'))), 0)), sumIf(deduped.latency, and(equals(deduped.event, '$ai_generation'), ifNull(greater(deduped.latency, 0), 0))), sumIf(deduped.latency, or(isNull(deduped.parent_id), ifNull(equals(deduped.parent_id, deduped.trace_id), isNull(deduped.parent_id)- and isNull(deduped.trace_id))))), 2) AS total_latency,- nullIf(sumIf(deduped.input_tokens, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 0) AS input_tokens,- nullIf(sumIf(deduped.output_tokens, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 0) AS output_tokens,- nullIf(round(sumIf(deduped.input_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS input_cost,- nullIf(round(sumIf(deduped.output_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS output_cost,- nullIf(round(sumIf(deduped.total_cost_usd, in(deduped.event, tuple('$ai_generation', '$ai_embedding'))), 10), 0) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(deduped.uuid, deduped.event, deduped.timestamp, deduped.properties, deduped.input, deduped.output, deduped.output_choices, deduped.input_state, deduped.output_state, deduped.tools), notEquals(deduped.event, '$ai_trace')))) AS events,- argMinIf(deduped.input_state, deduped.timestamp, equals(deduped.event, '$ai_trace')) AS input_state,- argMinIf(deduped.output_state, deduped.timestamp, equals(deduped.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(nullIf(deduped.span_name, ''), nullIf(deduped.trace_name, '')), deduped.timestamp, equals(deduped.event, '$ai_trace')), argMin(ifNull(nullIf(deduped.span_name, ''), nullIf(deduped.trace_name, '')), deduped.timestamp)) AS trace_name- FROM- (SELECT __ai_events_fallback.uuid AS uuid,- __ai_events_fallback.event AS event,- toTimeZone(__ai_events_fallback.timestamp, 'UTC') AS timestamp,- __ai_events_fallback.distinct_id AS distinct_id,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(__ai_events_fallback.properties)))), ','), '}') AS properties,- __ai_events_fallback.properties.`$ai_trace_id` AS trace_id,- __ai_events_fallback.properties.`$ai_session_id` AS session_id,- __ai_events_fallback.properties.`$ai_parent_id` AS parent_id,- if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_span_name`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_span_name`), if(isNull(__ai_events_fallback.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_span_name`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_span_name`), toString(__ai_events_fallback.properties.`$ai_span_name`))))) AS span_name,- if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_trace_name`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_trace_name`), if(isNull(__ai_events_fallback.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_trace_name`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_trace_name`), toString(__ai_events_fallback.properties.`$ai_trace_name`))))) AS trace_name,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_latency`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_latency`), if(isNull(__ai_events_fallback.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_latency`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_latency`), toString(__ai_events_fallback.properties.`$ai_latency`))))), 'Float64'), 'Float64') AS latency,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_tokens`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_tokens`), if(isNull(__ai_events_fallback.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_input_tokens`), toString(__ai_events_fallback.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64') AS input_tokens,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_tokens`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_tokens`), if(isNull(__ai_events_fallback.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_output_tokens`), toString(__ai_events_fallback.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64') AS output_tokens,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_cost_usd`), if(isNull(__ai_events_fallback.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_input_cost_usd`), toString(__ai_events_fallback.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64') AS input_cost_usd,- accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_cost_usd`), if(isNull(__ai_events_fallback.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(__ai_events_fallback.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(__ai_events_fallback.properties.`$ai_output_cost_usd`), toString(__ai_events_fallback.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64') AS output_cost_usd,- accurateCastOrNull(accurateCastOrNull(__ai_events_fallback.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64') AS total_cost_usd,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input`), if(isNull(__ai_events_fallback.properties.`$ai_input`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_input`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_input`)))), '')) AS input,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output`), if(isNull(__ai_events_fallback.properties.`$ai_output`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output`)))), '')) AS output,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_choices`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_choices`), if(isNull(__ai_events_fallback.properties.`$ai_output_choices`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_choices`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output_choices`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output_choices`)))), '')) AS output_choices,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_input_state`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_input_state`), if(isNull(__ai_events_fallback.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_input_state`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_input_state`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_input_state`)))), '')) AS input_state,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_output_state`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_output_state`), if(isNull(__ai_events_fallback.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_output_state`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_output_state`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_output_state`)))), '')) AS output_state,- JSONExtractRaw(ifNull(if(notEquals(toJSONString(__ai_events_fallback.properties.^`$ai_tools`), '{}'), toJSONString(__ai_events_fallback.properties.^`$ai_tools`), if(isNull(__ai_events_fallback.properties.`$ai_tools`), NULL, if(startsWith(dynamicType(__ai_events_fallback.properties.`$ai_tools`), 'DateTime'), concat('"', ifNull(toString(replaceOne(toString(__ai_events_fallback.properties.`$ai_tools`), ' ', 'T')), ''), '"'), toJSONString(__ai_events_fallback.properties.`$ai_tools`)))), '')) AS tools- FROM events_json AS __ai_events_fallback- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS __ai_events_fallback__override ON equals(__ai_events_fallback.distinct_id, __ai_events_fallback__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'bar'), ''), 'null'), '^"|"$', '') AS properties___bar- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS __ai_events_fallback__person ON equals(if(not(empty(__ai_events_fallback__override.distinct_id)), __ai_events_fallback__override.person_id, __ai_events_fallback.person_id), __ai_events_fallback__person.id)- WHERE and(equals(__ai_events_fallback.team_id, 99999), in(__ai_events_fallback.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(__ai_events_fallback.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(__ai_events_fallback.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC'))), equals(__ai_events_fallback.properties.`$ai_trace_id`, 'trace1'), ifNull(equals(__ai_events_fallback__person.properties___bar, 'foo'), 0)))- LIMIT 1 BY __ai_events_fallback.uuid) AS deduped- GROUP BY deduped.trace_id- LIMIT 1 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_traces_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_traces_query_runner.ambrindex f69981660d2d..e54f6d0d0bb3 100644--- a/posthog/hogql_queries/ai/test/__snapshots__/test_traces_query_runner.ambr+++ b/posthog/hogql_queries/ai/test/__snapshots__/test_traces_query_runner.ambr@@ -71,78 +71,6 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_field_mapping[new_events_schema.1]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-13 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 01:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace1', 'trace2')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_field_mapping[new_events_schema]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestTracesQueryRunner.test_group_key_filter'''SELECT groupArray(trace_id) AS trace_ids,@@ -460,64 +388,21 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.1]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-14 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 02:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_project_1', 'trace_org_b', 'trace_org_a')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.2]+# name: TestTracesQueryRunner.test_pagination'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,max(last_ts) AS max_timestampFROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,+ (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC')))), equals(events.`$group_0`, 'org:acme')))+ FROM events+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))GROUP BY trace_idHAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)+ LIMIT 5)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -532,35 +417,35 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.3]+# name: TestTracesQueryRunner.test_pagination.1'''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,+ SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-14 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 00:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_org_a')))- GROUP BY events.properties.`$ai_trace_id`+ round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,+ arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,+ ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,+ countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,+ arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools+ FROM events+ WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 05:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6')))+ GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')ORDER BY first_timestamp DESC- LIMIT 101+ LIMIT 5OFFSET 0 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -575,21 +460,21 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.4]+# name: TestTracesQueryRunner.test_pagination.2'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,max(last_ts) AS max_timestampFROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,+ (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC')))), equals(events.`$group_0`, 'org:widgets')))+ FROM events+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))GROUP BY trace_idHAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)+ LIMIT 10)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -604,36 +489,36 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.5]+# name: TestTracesQueryRunner.test_pagination.3'''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,+ SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 00:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 01:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_org_b')))- GROUP BY events.properties.`$ai_trace_id`+ round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,+ arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,+ ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,+ countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,+ arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools+ FROM events+ WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 00:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1')))+ GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,+ LIMIT 5+ OFFSET 5 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,@@ -647,21 +532,21 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.6]+# name: TestTracesQueryRunner.test_pagination.4'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,max(last_ts) AS max_timestampFROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,+ (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC')))), equals(events.`$group_1`, 'project:alpha')))+ FROM events+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))GROUP BY trace_idHAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)+ LIMIT 15)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -676,94 +561,36 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.7]+# name: TestTracesQueryRunner.test_pagination.5'''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,+ SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 01:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 02:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_project_1')))- GROUP BY events.properties.`$ai_trace_id`+ round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,+ sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,+ round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,+ round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,+ arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))+ and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,+ argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,+ ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,+ countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,+ any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,+ arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools+ FROM events+ WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-14 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1', 'trace_0')))+ GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema.8]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC')))), equals(events.`$group_0`, 'nonexistent')))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_group_key_filter[new_events_schema]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,+ LIMIT 5+ OFFSET 10 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,@@ -777,7 +604,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination+# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,@@ -787,11 +614,11 @@min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_tsFROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))+ HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 5)+ LIMIT 101)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -806,7 +633,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination.1+# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.1'''SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,@@ -831,10 +658,10 @@any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS toolsFROM events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 05:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6')))+ WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace1')))GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')ORDER BY first_timestamp DESC- LIMIT 5+ LIMIT 101OFFSET 0 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -849,7 +676,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination.2+# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.2'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,@@ -859,11 +686,11 @@min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_tsFROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'baz'), 0)))GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))+ HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 10)+ LIMIT 101)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -878,7 +705,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination.3+# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.3'''SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,@@ -903,11 +730,11 @@any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS toolsFROM events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 00:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1')))+ WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace1')))GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')ORDER BY first_timestamp DESC- LIMIT 5- OFFSET 5 SETTINGS readonly=2,+ LIMIT 101+ OFFSET 0 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,@@ -921,7 +748,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination.4+# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.4'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,@@ -931,11 +758,11 @@min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,max(toTimeZone(events.timestamp, 'UTC')) AS last_tsFROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))+ WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'barz'), 0)))GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))+ HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 15)+ LIMIT 101)LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -950,612 +777,7 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_pagination.5- '''- SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools- FROM events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-14 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1', 'trace_0')))- GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')- ORDER BY first_timestamp DESC- LIMIT 5- OFFSET 10 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema.1]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 05:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 5- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema.2]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 10)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema.3]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 00:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 5- OFFSET 5 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema.4]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 15)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema.5]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-14 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-15 10:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace_10', 'trace_9', 'trace_8', 'trace_7', 'trace_6', 'trace_5', 'trace_4', 'trace_3', 'trace_2', 'trace_1', 'trace_0')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 5- OFFSET 10 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_pagination[new_events_schema]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-08 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2025-01-16 00:10:59', 'UTC'))))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-16 00:00:59', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2025-01-09 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 5)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.1- '''- SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools- FROM events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace1')))- GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.2- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'baz'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.3- '''- SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS id,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_session_id'), ''), 'null'), '^"|"$', '')) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_latency'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_tokens'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_request_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_web_search_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_total_cost_usd'), ''), 'null'), '^"|"$', ''), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), events.properties), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), ifNull(equals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')), toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''))), isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_parent_id'), ''), 'null'), '^"|"$', '')))- and isNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')))))))) AS events,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_input_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_output_state'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_span_name'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_name'), ''), 'null'), '^"|"$', '')), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_error'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_is_error'), ''), 'null'), '^"|"$', ''), 'true'), 0))) AS error_count,- any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'ai_support_impersonated'), ''), 'null'), '^"|"$', '')) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), and(equals(events.event, '$ai_generation'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_tools_called'), ''), 'null'), '^"|"$', '')), ''), 1))), ',')))) AS tools- FROM events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), tuple('trace1')))- GROUP BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group.4- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '') AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', '')), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$ai_trace_id'), ''), 'null'), '^"|"$', ''), ''), 1), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'barz'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group[new_events_schema.1]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace1')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group[new_events_schema.2]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(if(notEquals(toJSONString(events.properties.^foo), '{}'), toJSONString(events.properties.^foo), if(isNull(events.properties.foo), NULL, if(startsWith(dynamicType(events.properties.foo), 'DateTime'), replaceOne(toString(events.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.foo), 'Array'), startsWith(dynamicType(events.properties.foo), 'Map'), startsWith(dynamicType(events.properties.foo), 'Tuple')), toJSONString(events.properties.foo), toString(events.properties.foo))))), 'baz'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group[new_events_schema.3]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace1')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group[new_events_schema.4]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(if(notEquals(toJSONString(events.properties.^foo), '{}'), toJSONString(events.properties.^foo), if(isNull(events.properties.foo), NULL, if(startsWith(dynamicType(events.properties.foo), 'DateTime'), replaceOne(toString(events.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.foo), 'Array'), startsWith(dynamicType(events.properties.foo), 'Map'), startsWith(dynamicType(events.properties.foo), 'Tuple')), toJSONString(events.properties.foo), toString(events.properties.foo))))), 'barz'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_properties_filter_with_multiple_events_in_group[new_events_schema]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(if(notEquals(toJSONString(events.properties.^foo), '{}'), toJSONString(events.properties.^foo), if(isNull(events.properties.foo), NULL, if(startsWith(dynamicType(events.properties.foo), 'DateTime'), replaceOne(toString(events.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.foo), 'Array'), startsWith(dynamicType(events.properties.foo), 'Map'), startsWith(dynamicType(events.properties.foo), 'Tuple')), toJSONString(events.properties.foo), toString(events.properties.foo))))), 'bar'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group+# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group'''SELECT groupArray(trace_id) AS trace_ids,min(first_ts) AS min_timestamp,@@ -1728,176 +950,3 @@use_hive_partitioning=0'''# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group[new_events_schema.1]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:55:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:15:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace1')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group[new_events_schema.2]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(if(notEquals(toJSONString(events.properties.^foo), '{}'), toJSONString(events.properties.^foo), if(isNull(events.properties.foo), NULL, if(startsWith(dynamicType(events.properties.foo), 'DateTime'), replaceOne(toString(events.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.foo), 'Array'), startsWith(dynamicType(events.properties.foo), 'Map'), startsWith(dynamicType(events.properties.foo), 'Tuple')), toJSONString(events.properties.foo), toString(events.properties.foo))))), 'bar'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group[new_events_schema.3]- '''- SELECT events.properties.`$ai_trace_id` AS id,- any(events.properties.`$ai_session_id`) AS ai_session_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_timestamp,- max(toTimeZone(events.timestamp, 'UTC')) AS last_timestamp,- ifNull(nullIf(argMinIf(events.distinct_id, toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), ''), argMin(events.distinct_id, toTimeZone(events.timestamp, 'UTC'))) AS first_distinct_id,- round(if(and(equals(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), notEquals(events.event, '$ai_generation'))), 0), greater(countIf(and(ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0), equals(events.event, '$ai_generation'))), 0)), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), and(equals(events.event, '$ai_generation'), ifNull(greater(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), 0), 0))), sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_latency`), '{}'), toJSONString(events.properties.^`$ai_latency`), if(isNull(events.properties.`$ai_latency`), NULL, if(startsWith(dynamicType(events.properties.`$ai_latency`), 'DateTime'), replaceOne(toString(events.properties.`$ai_latency`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_latency`), 'Array'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Map'), startsWith(dynamicType(events.properties.`$ai_latency`), 'Tuple')), toJSONString(events.properties.`$ai_latency`), toString(events.properties.`$ai_latency`))))), 'Float64'), 'Float64'), or(isNull(events.properties.`$ai_parent_id`), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`))))), 2) AS total_latency,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_tokens`), '{}'), toJSONString(events.properties.^`$ai_input_tokens`), if(isNull(events.properties.`$ai_input_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_input_tokens`), toString(events.properties.`$ai_input_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS input_tokens,- sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_tokens`), '{}'), toJSONString(events.properties.^`$ai_output_tokens`), if(isNull(events.properties.`$ai_output_tokens`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_tokens`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_tokens`), 'Tuple')), toJSONString(events.properties.`$ai_output_tokens`), toString(events.properties.`$ai_output_tokens`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))) AS output_tokens,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_input_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_input_cost_usd`), if(isNull(events.properties.`$ai_input_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_input_cost_usd`), toString(events.properties.`$ai_input_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS input_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_output_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_output_cost_usd`), if(isNull(events.properties.`$ai_output_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_output_cost_usd`), toString(events.properties.`$ai_output_cost_usd`))))), 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS output_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_request_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_request_cost_usd`), if(isNull(events.properties.`$ai_request_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_request_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_request_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_request_cost_usd`), toString(events.properties.`$ai_request_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS request_cost,- round(sumIf(accurateCastOrNull(if(notEquals(toJSONString(events.properties.^`$ai_web_search_cost_usd`), '{}'), toJSONString(events.properties.^`$ai_web_search_cost_usd`), if(isNull(events.properties.`$ai_web_search_cost_usd`), NULL, if(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'DateTime'), replaceOne(toString(events.properties.`$ai_web_search_cost_usd`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Array'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Map'), startsWith(dynamicType(events.properties.`$ai_web_search_cost_usd`), 'Tuple')), toJSONString(events.properties.`$ai_web_search_cost_usd`), toString(events.properties.`$ai_web_search_cost_usd`))))), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS web_search_cost,- round(sumIf(accurateCastOrNull(accurateCastOrNull(events.properties.`$ai_total_cost_usd`, 'Float64'), 'Float64'), in(events.event, tuple('$ai_generation', '$ai_embedding'))), 10) AS total_cost,- arrayDistinct(arraySort(x -> x.3, groupArrayIf(tuple(events.uuid, events.event, toTimeZone(events.timestamp, 'UTC'), concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}')), or(in(events.event, tuple('$ai_metric', '$ai_feedback')), equals(toString(events.properties.`$ai_parent_id`), toString(events.properties.`$ai_trace_id`)))))) AS events,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_input_state`), '{}'), toJSONString(events.properties.^`$ai_input_state`), if(isNull(events.properties.`$ai_input_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_input_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_input_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_input_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_input_state`), 'Tuple')), toJSONString(events.properties.`$ai_input_state`), toString(events.properties.`$ai_input_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS input_state,- argMinIf(if(notEquals(toJSONString(events.properties.^`$ai_output_state`), '{}'), toJSONString(events.properties.^`$ai_output_state`), if(isNull(events.properties.`$ai_output_state`), NULL, if(startsWith(dynamicType(events.properties.`$ai_output_state`), 'DateTime'), replaceOne(toString(events.properties.`$ai_output_state`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_output_state`), 'Array'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Map'), startsWith(dynamicType(events.properties.`$ai_output_state`), 'Tuple')), toJSONString(events.properties.`$ai_output_state`), toString(events.properties.`$ai_output_state`))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')) AS output_state,- ifNull(argMinIf(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'), equals(events.event, '$ai_trace')), argMin(ifNull(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), if(notEquals(toJSONString(events.properties.^`$ai_trace_name`), '{}'), toJSONString(events.properties.^`$ai_trace_name`), if(isNull(events.properties.`$ai_trace_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_trace_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_trace_name`), 'Tuple')), toJSONString(events.properties.`$ai_trace_name`), toString(events.properties.`$ai_trace_name`)))))), toTimeZone(events.timestamp, 'UTC'))) AS trace_name,- countIf(or(isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_error`), '{}'), toJSONString(events.properties.^`$ai_error`), if(isNull(events.properties.`$ai_error`), NULL, if(startsWith(dynamicType(events.properties.`$ai_error`), 'DateTime'), replaceOne(toString(events.properties.`$ai_error`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_error`), 'Array'), startsWith(dynamicType(events.properties.`$ai_error`), 'Map'), startsWith(dynamicType(events.properties.`$ai_error`), 'Tuple')), toJSONString(events.properties.`$ai_error`), toString(events.properties.`$ai_error`)))))), equals(events.properties.`$ai_is_error`, 'true'))) AS error_count,- any(if(notEquals(toJSONString(events.properties.^ai_support_impersonated), '{}'), toJSONString(events.properties.^ai_support_impersonated), if(isNull(events.properties.ai_support_impersonated), NULL, if(startsWith(dynamicType(events.properties.ai_support_impersonated), 'DateTime'), replaceOne(toString(events.properties.ai_support_impersonated), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.ai_support_impersonated), 'Array'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Map'), startsWith(dynamicType(events.properties.ai_support_impersonated), 'Tuple')), toJSONString(events.properties.ai_support_impersonated), toString(events.properties.ai_support_impersonated)))))) AS is_support_trace,- arrayFilter(x -> ifNull(notEquals(x, ''), 1), arrayDistinct(splitByChar(',', arrayStringConcat(groupArrayIf(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), and(equals(events.event, '$ai_generation'), isNotNull(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ifNull(notEquals(toString(if(notEquals(toJSONString(events.properties.^`$ai_tools_called`), '{}'), toJSONString(events.properties.^`$ai_tools_called`), if(isNull(events.properties.`$ai_tools_called`), NULL, if(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'DateTime'), replaceOne(toString(events.properties.`$ai_tools_called`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Array'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Map'), startsWith(dynamicType(events.properties.`$ai_tools_called`), 'Tuple')), toJSONString(events.properties.`$ai_tools_called`), toString(events.properties.`$ai_tools_called`)))))), ''), 1))), ',')))) AS tools- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), and(in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:52:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:12:00', 'UTC'))))), in(events.properties.`$ai_trace_id`, tuple('trace1')))- GROUP BY events.properties.`$ai_trace_id`- ORDER BY first_timestamp DESC- LIMIT 101- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group[new_events_schema.4]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), and(ifNull(equals(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), 'runnable'), 0), ifNull(equals(if(notEquals(toJSONString(events.properties.^foo), '{}'), toJSONString(events.properties.^foo), if(isNull(events.properties.foo), NULL, if(startsWith(dynamicType(events.properties.foo), 'DateTime'), replaceOne(toString(events.properties.foo), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.foo), 'Array'), startsWith(dynamicType(events.properties.foo), 'Map'), startsWith(dynamicType(events.properties.foo), 'Tuple')), toJSONString(events.properties.foo), toString(events.properties.foo))))), 'bar'), 0))))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestTracesQueryRunner.test_trace_property_filter_for_event_group[new_events_schema]- '''- SELECT groupArray(trace_id) AS trace_ids,- min(first_ts) AS min_timestamp,- max(last_ts) AS max_timestamp- FROM- (SELECT events.properties.`$ai_trace_id` AS trace_id,- min(toTimeZone(events.timestamp, 'UTC')) AS first_ts,- max(toTimeZone(events.timestamp, 'UTC')) AS last_ts- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), in(events.event, tuple('$ai_span', '$ai_generation', '$ai_embedding', '$ai_metric', '$ai_feedback', '$ai_trace')), and(isNotNull(events.properties.`$ai_trace_id`), notEquals(events.properties.`$ai_trace_id`, ''), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-11-30 23:50:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-12-01 00:20:00', 'UTC')))), ifNull(equals(if(notEquals(toJSONString(events.properties.^`$ai_span_name`), '{}'), toJSONString(events.properties.^`$ai_span_name`), if(isNull(events.properties.`$ai_span_name`), NULL, if(startsWith(dynamicType(events.properties.`$ai_span_name`), 'DateTime'), replaceOne(toString(events.properties.`$ai_span_name`), ' ', 'T'), if(or(startsWith(dynamicType(events.properties.`$ai_span_name`), 'Array'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Map'), startsWith(dynamicType(events.properties.`$ai_span_name`), 'Tuple')), toJSONString(events.properties.`$ai_span_name`), toString(events.properties.`$ai_span_name`))))), 'runnable'), 0)))- GROUP BY trace_id- HAVING and(lessOrEquals(min(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:10:00', 'UTC'))), greaterOrEquals(max(toTimeZone(events.timestamp, 'UTC')), assumeNotNull(toDateTime('2024-12-01 00:00:00', 'UTC'))))- ORDER BY min(toTimeZone(events.timestamp, 'UTC')) DESC- LIMIT 101)- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr b/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambrindex 4b1113108488..c1c5a43f7714 100644--- a/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr+++ b/posthog/hogql_queries/groups/test/__snapshots__/test_groups_query_runner.ambr@@ -59,33 +59,6 @@use_hive_partitioning=0'''# ----# name: TestGroupsQueryRunner.test_groups_query_runner_search_ranking- '''- SELECT coalesce(toString(groups.properties___name), toString(groups.key)) AS `coalesce(toString(properties.name), toString(key))`,- groups.key AS key- FROM- (SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', ''), toTimeZone(groups._timestamp, 'UTC')) AS properties___name,- argMax(toTimeZone(groups.created_at, 'UTC'), toTimeZone(groups._timestamp, 'UTC')) AS created_at,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE and(ifNull(equals(groups.index, 0), 0), or(ifNull(ilike(groups.properties___name, '%test%'), 0), ilike(toString(groups.key), '%test%')))- ORDER BY multiIf(ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'test'), 0), 0, ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'test%'), 0), 1, 2) ASC, groups.created_at DESC- LIMIT 11- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1- '''-# ---# name: TestGroupsQueryRunner.test_groups_query_runner_with_numeric_property'''SELECT tuple(coalesce(toString(groups.properties___name), toString(groups.key)), toString(groups.key)) AS `tuple(coalesce(toString(properties.name), toString(key)), toString(key))`,@@ -267,33 +240,6 @@use_hive_partitioning=0'''# ----# name: TestGroupsQueryRunner.test_groups_query_runner_with_search- '''- SELECT coalesce(toString(groups.properties___name), toString(groups.key)) AS `coalesce(toString(properties.name), toString(key))`,- groups.key AS key- FROM- (SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', ''), toTimeZone(groups._timestamp, 'UTC')) AS properties___name,- argMax(toTimeZone(groups.created_at, 'UTC'), toTimeZone(groups._timestamp, 'UTC')) AS created_at,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE and(ifNull(equals(groups.index, 0), 0), or(ifNull(ilike(groups.properties___name, '%org2%'), 0), ilike(toString(groups.key), '%org2%')))- ORDER BY multiIf(ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'org2'), 0), 0, ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'org2%'), 0), 1, 2) ASC, groups.created_at DESC- LIMIT 11- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1- '''-# ---# name: TestGroupsQueryRunner.test_groups_query_runner_with_string_property'''SELECT tuple(coalesce(toString(groups.properties___name), toString(groups.key)), toString(groups.key)) AS `tuple(coalesce(toString(properties.name), toString(key)), toString(key))`@@ -384,35 +330,6 @@use_hive_partitioning=0'''# ----# name: TestGroupsQueryRunner.test_search_ordering_with_user_orderby.1- '''- SELECT coalesce(toString(groups.properties___name), toString(groups.key)) AS `coalesce(toString(properties.name), toString(key))`,- groups.key AS key,- groups.properties___arr AS arr- FROM- (SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'name'), ''), 'null'), '^"|"$', ''), toTimeZone(groups._timestamp, 'UTC')) AS properties___name,- argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'arr'), ''), 'null'), '^"|"$', ''), toTimeZone(groups._timestamp, 'UTC')) AS properties___arr,- argMax(toTimeZone(groups.created_at, 'UTC'), toTimeZone(groups._timestamp, 'UTC')) AS created_at,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE and(ifNull(equals(groups.index, 0), 0), or(ifNull(ilike(groups.properties___name, '%test%'), 0), ilike(toString(groups.key), '%test%')))- ORDER BY multiIf(ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'test'), 0), 0, ifNull(ilike(coalesce(toString(groups.properties___name), toString(groups.key)), 'test%'), 0), 1, 2) ASC, groups.created_at DESC- LIMIT 11- OFFSET 0 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1- '''-# ---# name: TestGroupsQueryRunner.test_search_ranking'''SELECT tuple(coalesce(toString(groups.properties___name), toString(groups.key)), toString(groups.key)) AS `tuple(coalesce(toString(properties.name), toString(key)), toString(key))`diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambrindex 46304b04155b..a746b2ae080c 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr@@ -58,65 +58,6 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_aggregation_with_groups[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFOSSFunnelUDF.test_funnel_aggregation_with_groups_across_persons'''SELECT sum(step_1) AS step_1,@@ -184,73 +125,6 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_aggregation_with_groups_across_persons[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFOSSFunnelUDF.test_funnel_conversion_window_seconds'''SELECT sum(step_1) AS step_1,@@ -383,65 +257,16 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_conversion_window_seconds[new_events_schema.1]+# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2'''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 15, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 1)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0++ SELECT DISTINCT person_id+ FROM events+ WHERE team_id = 99999+ AND distinct_id = 'stopped_after_pay''''# ----# name: TestFOSSFunnelUDF.test_funnel_conversion_window_seconds[new_events_schema]+# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2.1'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,@@ -465,7 +290,7 @@FROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(3, 15, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -478,10 +303,10 @@e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(equals(e.event, 'step one'), 1, 0) AS step_0,- if(equals(e.event, 'step two'), 1, 0) AS step_1,- if(equals(e.event, 'step three'), 1, 0) AS step_2- FROM events_json AS e+ if(equals(e.event, 'user signed up'), 1, 0) AS step_0,+ if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), e.elements_chain_texts)), 1, 0) AS step_1,+ if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)a(\\.|$|;|:)'), equals(e.elements_chain_href, '/movie')), 1, 0) AS step_2+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -489,7 +314,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('step one', 'step three', 'step two'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$autocapture', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -515,40 +340,36 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2+# name: TestFOSSFunnelUDF.test_funnel_with_precalculated_cohort_step_filter'''- SELECT DISTINCT person_id- FROM events+ SELECT count(DISTINCT person_id)+ FROM cohortpeopleWHERE team_id = 99999- AND distinct_id = 'stopped_after_pay'+ AND cohort_id = 99999+ AND version = 0'''# ----# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2.1+# name: TestFOSSFunnelUDF.test_funnel_with_precalculated_cohort_step_filter.1'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,- sum(step_3) AS step_3,arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,groupArray(row_number) AS row_number,final_prop AS final_propFROM(SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,rowNumberInAllBlocks() AS row_number,breakdown AS final_propFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -561,9 +382,11 @@e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), e.elements_chain_texts)), 1, 0) AS step_1,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)a(\\.|$|;|:)'), equals(e.elements_chain_href, '/movie')), 1, 0) AS step_2+ if(and(equals(e.event, 'user signed up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),+ (SELECT cohortpeople.person_id AS person_id+ FROM cohortpeople+ WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))), 1, 0) AS step_0,+ if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -572,16 +395,14 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$autocapture', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,+ ORDER BY step_2 DESC,step_1 DESC)GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,+ ORDER BY step_2 DESC,step_1 DESCLIMIT 100 SETTINGS join_algorithm='auto',readonly=2,@@ -598,7 +419,7 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2[new_events_schema.1]+# name: TestFOSSFunnelUDF.test_funnel_with_property_groups'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,@@ -607,6 +428,7 @@arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,groupArray(row_number) AS row_number,final_prop AS final_propFROM@@ -615,16 +437,13 @@countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,rowNumberInAllBlocks() AS row_number,breakdown AS final_propFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -638,17 +457,28 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), e.elements_chain_texts)), 1, 0) AS step_1,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)a(\\.|$|;|:)'), equals(e.elements_chain_href, '/movie')), 1, 0) AS step_2- FROM events_json AS e+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2+ FROM events AS eLEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$autocapture', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -674,27 +504,14 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_events_with_person_on_events_v2[new_events_schema]+# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.1'''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop+ SELECT source.id,+ source.id AS id,+ 1FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop+ (SELECT aggregation_target AS actor_id,+ actor_id AS idFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[''] AS prop,@@ -712,9 +529,9 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)button(\\.|$|;|:)'), arrayExists(x -> ifNull(equals(x, 'Pay $10'), 0), e.elements_chain_texts)), 1, 0) AS step_1,- if(and(equals(e.event, '$autocapture'), match(e.elements_chain, '(^|;)a(\\.|$|;|:)'), equals(e.elements_chain_href, '/movie')), 1, 0) AS step_2- FROM events_json AS e+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -722,43 +539,189 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$autocapture', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0+ WHERE bitTest(steps_bitfield, 0)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_with_precalculated_cohort_step_filter+# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.2'''-- SELECT count(DISTINCT person_id)- FROM cohortpeople+ SELECT source.id,+ source.id AS id,+ 1+ FROM+ (SELECT aggregation_target AS actor_id,+ actor_id AS id+ FROM+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,+ [''] AS prop,+ arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ af_tuple.1 AS step_reached,+ plus(af_tuple.1, 1) AS steps,+ af_tuple.2 AS breakdown,+ af_tuple.3 AS timings,+ af_tuple.5 AS steps_bitfield,+ aggregation_target AS aggregation_target+ FROM+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.uuid AS uuid,+ e.`$session_id` AS `$session_id`,+ e.`$window_id` AS `$window_id`,+ if(equals(e.event, 'user signed up'), 1, 0) AS step_0,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,+ person_distinct_id_overrides.distinct_id AS distinct_id+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ GROUP BY aggregation_target+ HAVING ifNull(greaterOrEquals(step_reached, 0), 0))+ WHERE bitTest(steps_bitfield, 1)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.3+ '''+ SELECT source.id,+ source.id AS id,+ 1+ FROM+ (SELECT aggregation_target AS actor_id,+ actor_id AS id+ FROM+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,+ [''] AS prop,+ arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ af_tuple.1 AS step_reached,+ plus(af_tuple.1, 1) AS steps,+ af_tuple.2 AS breakdown,+ af_tuple.3 AS timings,+ af_tuple.5 AS steps_bitfield,+ aggregation_target AS aggregation_target+ FROM+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,+ if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.uuid AS uuid,+ e.`$session_id` AS `$session_id`,+ e.`$window_id` AS `$window_id`,+ if(equals(e.event, 'user signed up'), 1, 0) AS step_0,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,+ if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2+ FROM events AS e+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,+ person_distinct_id_overrides.distinct_id AS distinct_id+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)+ LEFT JOIN+ (SELECT person.id AS id,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,+ replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age+ FROM person+ WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),+ (SELECT person.id AS id, max(person.version) AS version+ FROM person+ WHERE equals(person.team_id, 99999)+ GROUP BY person.id+ HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ GROUP BY aggregation_target+ HAVING ifNull(greaterOrEquals(step_reached, 0), 0))+ WHERE bitTest(steps_bitfield, 2)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestFOSSFunnelUDF.test_funnel_with_static_cohort_step_filter+ '''+ SELECT person_id+ FROM person_static_cohortWHERE team_id = 99999AND cohort_id = 99999- AND version = 0+ AND person_id IN ['00000000-0000-4000-8000-000000000001']+ GROUP BY person_id'''# ----# name: TestFOSSFunnelUDF.test_funnel_with_precalculated_cohort_step_filter.1+# name: TestFOSSFunnelUDF.test_funnel_with_static_cohort_step_filter.1'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,@@ -791,9 +754,9 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(and(equals(e.event, 'user signed up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))), 1, 0) AS step_0,+ (SELECT person_static_cohort.person_id AS person_id+ FROM person_static_cohort+ WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, 99999))))), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS eLEFT OUTER JOIN@@ -827,7 +790,7 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_with_precalculated_cohort_step_filter[new_events_schema]+# name: TestFOSSFunnelUDF.test_timezones'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,@@ -854,17 +817,14 @@af_tuple.5 AS steps_bitfield,aggregation_target AS aggregation_targetFROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,+ (SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT cohortpeople.person_id AS person_id- FROM cohortpeople- WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0))))), 1, 0) AS step_0,+ if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -872,7 +832,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -896,1544 +856,26 @@use_hive_partitioning=0'''# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups+# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen'''SELECT sum(step_1) AS step_1,sum(step_2) AS step_2,- sum(step_3) AS step_3,arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,groupArray(row_number) AS row_number,final_prop AS final_propFROM(SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.1- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.2- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 1)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups.3- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha.com'), 0)), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$current_url'), ''), 'null'), '^"|"$', ''), 'aloha2.com'), 0)), 1, 0) AS step_2- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 2)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups[new_events_schema.1]- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha2.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups[new_events_schema.2]- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha2.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 1)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups[new_events_schema.3]- '''- SELECT source.id,- source.id AS id,- 1- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha2.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 2)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_property_groups[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_1,- if(and(equals(e.event, '$pageview'), and(equals(e.properties.`$current_url`, 'aloha2.com'), isNotNull(e.properties.`$current_url`))), 1, 0) AS step_2- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(toString(e__person.properties___email), '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(toString(e__person.properties___email), '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_static_cohort_step_filter- '''- SELECT person_id- FROM person_static_cohort- WHERE team_id = 99999- AND cohort_id = 99999- AND person_id IN ['00000000-0000-4000-8000-000000000001']- GROUP BY person_id- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_static_cohort_step_filter.1- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT person_static_cohort.person_id AS person_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, 99999))))), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_funnel_with_static_cohort_step_filter[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id),- (SELECT person_static_cohort.person_id AS person_id- FROM person_static_cohort- WHERE and(equals(person_static_cohort.team_id, 99999), equals(person_static_cohort.cohort_id, 99999))))), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_timezones- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFOSSFunnelUDF.test_timezones[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- breakdown AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'US/Pacific') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'US/Pacific'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 100 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,- [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(and(equals(e.event, 'buy'), ifNull(equals(if(notEquals(toJSONString(e.properties.^`$version`), '{}'), toJSONString(e.properties.^`$version`), if(isNull(e.properties.`$version`), NULL, if(startsWith(dynamicType(e.properties.`$version`), 'DateTime'), replaceOne(toString(e.properties.`$version`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$version`), 'Array'), startsWith(dynamicType(e.properties.`$version`), 'Map'), startsWith(dynamicType(e.properties.`$version`), 'Tuple')), toJSONString(e.properties.`$version`), toString(e.properties.`$version`))))), 'xyz'), 0)), 1, 0) AS step_1,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,- [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,- if(equals(step_1, 1), prop_basic, []) AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(and(equals(e.event, 'buy'), ifNull(equals(if(notEquals(toJSONString(e.properties.^`$version`), '{}'), toJSONString(e.properties.^`$version`), if(isNull(e.properties.`$version`), NULL, if(startsWith(dynamicType(e.properties.`$version`), 'DateTime'), replaceOne(toString(e.properties.`$version`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$version`), 'Array'), startsWith(dynamicType(e.properties.`$version`), 'Map'), startsWith(dynamicType(e.properties.`$version`), 'Tuple')), toJSONString(e.properties.`$version`), toString(e.properties.`$version`))))), 'xyz'), 0)), 1, 0) AS step_1,- [ifNull(toString(e.properties.`$browser`), '')] AS prop_basic,- if(equals(step_1, 1), prop_basic, []) AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_step_multiple_breakdown_snapshot- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), ['', ''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'buy'), 1, 0) AS step_1,- [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelBreakdownUDF.test_funnel_step_multiple_breakdown_snapshot[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), ['', ''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'buy'), 1, 0) AS step_1,- [ifNull(toString(e.properties.`$browser`), ''), ifNull(toString(if(notEquals(toJSONString(e.properties.^`$version`), '{}'), toJSONString(e.properties.^`$version`), if(isNull(e.properties.`$version`), NULL, if(startsWith(dynamicType(e.properties.`$version`), 'DateTime'), replaceOne(toString(e.properties.`$version`), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.`$version`), 'Array'), startsWith(dynamicType(e.properties.`$version`), 'Map'), startsWith(dynamicType(e.properties.`$version`), 'Tuple')), toJSONString(e.properties.`$version`), toString(e.properties.`$version`)))))), '')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_aggregate_by_groups_breakdown_group_person_on_events- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_aggregate_by_groups_breakdown_group_person_on_events[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_aggregate_by_groups_breakdown_group_person_on_events_poe_v2- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- max(total_median_conversion_time) AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(total_conversion_times) OVER ()))])[1] AS total_median_conversion_time,- rowNumberInAllBlocks() AS row_number,- if(ifNull(less(row_number, 25), 0), breakdown, 'Other') AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- enable_analyzer=1,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop+ if(less(row_number, 25), breakdown, ['Other']) AS final_propFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,+ argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,+ arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -2447,9 +889,8 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,+ if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,+ [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,prop_basic AS propFROM events AS eLEFT OUTER JOIN@@ -2459,24 +900,14 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,+ ORDER BY step_2 DESC,step_1 DESC)GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,+ ORDER BY step_2 DESC,step_1 DESCLIMIT 26 SETTINGS join_algorithm='auto',readonly=2,@@ -2493,88 +924,26 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.1- '''- SELECT source.id,- source.id AS id- FROM- (SELECT aggregation_target AS actor_id,- actor_id AS id- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop- FROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.2+# name: TestFunnelBreakdownUDF.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step'''- SELECT source.id,- source.id AS id+ SELECT sum(step_1) AS step_1,+ sum(step_2) AS step_2,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,+ groupArray(row_number) AS row_number,+ final_prop AS final_propFROM- (SELECT aggregation_target AS actor_id,- actor_id AS id+ (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,+ groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,+ rowNumberInAllBlocks() AS row_number,+ if(less(row_number, 25), breakdown, ['Other']) AS final_propFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,+ groupUniqArrayIf(arrayMap(x -> ifNull(x, ''), prop), notEmpty(prop)) AS prop,+ arrayJoin(aggregate_funnel_array(2, 1209600, 'step_1', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -2588,10 +957,9 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,- prop_basic AS prop+ if(and(equals(e.event, 'buy'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', ''), 'xyz'), 0)), 1, 0) AS step_1,+ [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,+ if(equals(step_1, 1), prop_basic, []) AS propFROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -2600,29 +968,22 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',+ GROUP BY breakdown+ ORDER BY step_2 DESC,+ step_1 DESC)+ GROUP BY final_prop+ ORDER BY step_2 DESC,+ step_1 DESC+ LIMIT 26 SETTINGS join_algorithm='auto',readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,+ max_bytes_before_external_group_by=23622320128,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,@@ -2631,19 +992,26 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.3+# name: TestFunnelBreakdownUDF.test_funnel_step_multiple_breakdown_snapshot'''- SELECT source.id,- source.id AS id+ SELECT sum(step_1) AS step_1,+ sum(step_2) AS step_2,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,+ groupArray(row_number) AS row_number,+ final_prop AS final_propFROM- (SELECT aggregation_target AS actor_id,- actor_id AS id+ (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,+ groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,+ rowNumberInAllBlocks() AS row_number,+ if(less(row_number, 25), breakdown, ['Other']) AS final_propFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,- [argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,- arrayJoin(aggregate_funnel(3, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,+ argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,+ arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), ['', ''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -2657,9 +1025,8 @@e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'sign up'), 1, 0) AS step_0,- if(equals(e.event, 'play movie'), 1, 0) AS step_1,- if(equals(e.event, 'buy'), 1, 0) AS step_2,- ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,+ if(equals(e.event, 'buy'), 1, 0) AS step_1,+ [ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$browser'), ''), 'null'), '^"|"$', '')), ''), ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$version'), ''), 'null'), '^"|"$', '')), '')] AS prop_basic,prop_basic AS propFROM events AS eLEFT OUTER JOIN@@ -2669,29 +1036,22 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',+ GROUP BY breakdown+ ORDER BY step_2 DESC,+ step_1 DESC)+ GROUP BY final_prop+ ORDER BY step_2 DESC,+ step_1 DESC+ LIMIT 26 SETTINGS join_algorithm='auto',readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,+ max_bytes_before_external_group_by=23622320128,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,@@ -2700,13 +1060,27 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.4+# name: TestFunnelGroupBreakdownUDF.test_funnel_aggregate_by_groups_breakdown_group_person_on_events'''- SELECT source.id,- source.id AS id+ SELECT sum(step_1) AS step_1,+ sum(step_2) AS step_2,+ sum(step_3) AS step_3,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,+ groupArray(row_number) AS row_number,+ final_prop AS final_propFROM- (SELECT aggregation_target AS actor_id,- actor_id AS id+ (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,+ groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,+ groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,+ rowNumberInAllBlocks() AS row_number,+ if(less(row_number, 25), breakdown, 'Other') AS final_propFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,@@ -2721,7 +1095,7 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,@@ -2731,13 +1105,6 @@ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS propFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)LEFT JOIN(SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,groups.group_type_index AS index,@@ -2746,21 +1113,24 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',+ GROUP BY breakdown+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC)+ GROUP BY final_prop+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC+ LIMIT 26 SETTINGS join_algorithm='auto',readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,+ max_bytes_before_external_group_by=23622320128,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,@@ -2769,13 +1139,27 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group[new_events_schema.1]+# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group'''- SELECT source.id,- source.id AS id+ SELECT sum(step_1) AS step_1,+ sum(step_2) AS step_2,+ sum(step_3) AS step_3,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,+ arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,+ groupArray(row_number) AS row_number,+ final_prop AS final_propFROM- (SELECT aggregation_target AS actor_id,- actor_id AS id+ (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,+ countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,+ groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,+ groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,+ groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,+ rowNumberInAllBlocks() AS row_number,+ if(less(row_number, 25), breakdown, 'Other') AS final_propFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,@@ -2799,7 +1183,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -2818,18 +1202,21 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',+ GROUP BY breakdown+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC)+ GROUP BY final_prop+ ORDER BY step_3 DESC,+ step_2 DESC,+ step_1 DESC+ LIMIT 26 SETTINGS join_algorithm='auto',readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,+ max_bytes_before_external_group_by=23622320128,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,@@ -2838,7 +1225,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group[new_events_schema.2]+# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.1'''SELECT source.id,source.id AS id@@ -2868,7 +1255,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -2887,7 +1274,7 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))+ WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS sourceORDER BY source.id ASCLIMIT 101@@ -2907,7 +1294,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group[new_events_schema.3]+# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.2'''SELECT source.id,source.id AS id@@ -2937,7 +1324,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -2956,7 +1343,7 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))+ WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('finance'))))ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS sourceORDER BY source.id ASCLIMIT 101@@ -2976,7 +1363,7 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group[new_events_schema.4]+# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.3'''SELECT source.id,source.id AS id@@ -3006,7 +1393,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -3025,7 +1412,7 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))+ WHERE and(bitTest(steps_bitfield, 0), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS sourceORDER BY source.id ASCLIMIT 101@@ -3045,27 +1432,13 @@use_hive_partitioning=0'''# ----# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group[new_events_schema]+# name: TestFunnelGroupBreakdownUDF.test_funnel_breakdown_group.4'''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- sum(step_3) AS step_3,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_2_conversion_times)])[1] AS step_2_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_2_conversion_times)])[1] AS step_2_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop+ SELECT source.id,+ source.id AS idFROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 4), 0), 1)) AS step_3,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(timings[2], ifNull(greater(timings[2], 0), 0)) AS step_2_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 2), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 25), breakdown, 'Other') AS final_prop+ (SELECT aggregation_target AS actor_id,+ actor_id AS idFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, ifNull(prop_basic, ''), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1), multiply(3, step_2)])))) AS events_array,[argMinIf(prop_basic, timestamp, isNotNull(prop_basic))] AS prop,@@ -3089,7 +1462,7 @@if(equals(e.event, 'buy'), 1, 0) AS step_2,ifNull(toString(e__group_0.properties___industry), '') AS prop_basic,prop_basic AS prop- FROM events_json AS e+ FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,person_distinct_id_overrides.distinct_id AS distinct_id@@ -3108,21 +1481,18 @@WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('buy', 'play movie', 'sign up'))), or(equals(step_0, 1), equals(step_1, 1), equals(step_2, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_3 DESC,- step_2 DESC,- step_1 DESC- LIMIT 26 SETTINGS join_algorithm='auto',+ WHERE and(bitTest(steps_bitfield, 1), equals(arrayFlatten(array(breakdown)), arrayFlatten(array('technology'))))+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto') AS source+ ORDER BY source.id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',readonly=2,max_execution_time=60,allow_experimental_object_type=1,max_ast_elements=4000000,max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,+ max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambrindex f6d01aaff05d..412efde766c0 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_breakdowns_by_current_url.ambr@@ -67,74 +67,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_current_url[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 100), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'watched movie'), 1, 0) AS step_0,- if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,- [if(empty(replaceRegexpOne(ifNull(toString(e.properties.`$current_url`), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(e.properties.`$current_url`), ''), '[\\/?#]*$', ''))] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('terminate funnel', 'watched movie'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 101 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname'''SELECT sum(step_1) AS step_1,@@ -203,74 +135,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 100), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'watched movie'), 1, 0) AS step_0,- if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,- [if(empty(replaceRegexpOne(ifNull(toString(e.properties.`$pathname`), ''), '[\\/?#]*$', '')), '/', replaceRegexpOne(ifNull(toString(e.properties.`$pathname`), ''), '[\\/?#]*$', ''))] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('terminate funnel', 'watched movie'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 101 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname_with_path_cleaning'''SELECT sum(step_1) AS step_1,@@ -339,74 +203,6 @@use_hive_partitioning=0'''# ----# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname_with_path_cleaning[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 100), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'watched movie'), 1, 0) AS step_0,- if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,- [if(empty(replaceRegexpOne(replaceRegexpAll(ifNull(toString(e.properties.`$pathname`), ''), '/home.*', '/cleaned-home'), '[\\/?#]*$', '')), '/', replaceRegexpOne(replaceRegexpAll(ifNull(toString(e.properties.`$pathname`), ''), '/home.*', '/cleaned-home'), '[\\/?#]*$', ''))] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('terminate funnel', 'watched movie'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 101 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname_with_path_cleaning_without_normalization'''SELECT sum(step_1) AS step_1,@@ -475,71 +271,3 @@use_hive_partitioning=0'''# ----# name: TestFunnelBreakdownsByCurrentURL.test_breakdown_by_pathname_with_path_cleaning_without_normalization[new_events_schema]- '''- SELECT sum(step_1) AS step_1,- sum(step_2) AS step_2,- arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time,- arrayMap(x -> if(isNaN(x), NULL, x), [arrayReduce('median', arrayFlatten(groupArray(arrayFlatten(groupArray(total_conversion_times))) OVER ()))])[1] AS total_median_conversion_time,- groupArray(row_number) AS row_number,- final_prop AS final_prop- FROM- (SELECT countIf(ifNull(notEquals(bitAnd(steps_bitfield, 1), 0), 1)) AS step_1,- countIf(ifNull(notEquals(bitAnd(steps_bitfield, 2), 0), 1)) AS step_2,- groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times,- groupArrayIf(arraySum(timings), ifNull(greaterOrEquals(step_reached, 1), 0)) AS total_conversion_times,- rowNumberInAllBlocks() AS row_number,- if(less(row_number, 100), breakdown, ['Other']) AS final_prop- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, arrayMap(x -> ifNull(x, ''), prop_basic), arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- argMinIf(prop_basic, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop_basic))) AS prop,- arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'ordered', [if(empty(prop), [''], prop)], [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'watched movie'), 1, 0) AS step_0,- if(equals(e.event, 'terminate funnel'), 1, 0) AS step_1,- [replaceRegexpAll(ifNull(toString(e.properties.`$pathname`), ''), '/home.*', '/cleaned-home')] AS prop_basic,- prop_basic AS prop- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('terminate funnel', 'watched movie'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- GROUP BY breakdown- ORDER BY step_2 DESC,- step_1 DESC)- GROUP BY final_prop- ORDER BY step_2 DESC,- step_1 DESC- LIMIT 101 SETTINGS join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=23622320128,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambrindex 47699c176c78..3d209c6f99b0 100644--- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr+++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr@@ -61,68 +61,6 @@use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_action_events_are_excluded_from_correlations[new_events_schema]- '''- WITH funnel_actors AS MATERIALIZED- (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(and(equals(e.event, 'user signed up'), ifNull(equals(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key))))), 'val'), 0)), 1, 0) AS step_0, if(and(equals(e.event, 'paid'), ifNull(equals(if(notEquals(toJSONString(e.properties.^key), '{}'), toJSONString(e.properties.^key), if(isNull(e.properties.key), NULL, if(startsWith(dynamicType(e.properties.key), 'DateTime'), replaceOne(toString(e.properties.key), ' ', 'T'), if(or(startsWith(dynamicType(e.properties.key), 'Array'), startsWith(dynamicType(e.properties.key), 'Map'), startsWith(dynamicType(e.properties.key), 'Tuple')), toJSONString(e.properties.key), toString(e.properties.key))))), 'val'), 0)), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events_json AS event- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS event__override ON equals(event.distinct_id, event__override.distinct_id)- JOIN funnel_actors ON equals(if(not(empty(event__override.distinct_id)), event__override.person_id, event.person_id), funnel_actors.actor_id)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties'''WITH funnel_actors AS@@ -638,11 +576,160 @@use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties[new_events_schema.1]+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_event_properties_and_groups'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ WITH funnel_actors AS+ (SELECT aggregation_target AS actor_id,+ (matched_events_array[1][1]).1 AS timestamp,+ nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,+ (matched_events_array[1][1]).1 AS first_timestamp,+ steps AS steps+ FROM+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,+ [''] AS prop,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ af_tuple.1 AS step_reached,+ plus(af_tuple.1, 1) AS steps,+ af_tuple.2 AS breakdown,+ af_tuple.3 AS timings,+ af_tuple.4 AS matched_event_uuids_array_array,+ groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,+ mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,+ arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,+ af_tuple.5 AS steps_bitfield,+ aggregation_target AS aggregation_target+ FROM+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,+ e.`$group_1` AS aggregation_target,+ e.uuid AS uuid,+ e.`$session_id` AS `$session_id`,+ e.`$window_id` AS `$window_id`,+ if(equals(e.event, 'user signed up'), 1, 0) AS step_0,+ if(equals(e.event, 'paid'), 1, 0) AS step_1+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))+ GROUP BY aggregation_target+ HAVING ifNull(greaterOrEquals(step_reached, 0), 0))+ WHERE bitTest(steps_bitfield, 0)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),+ filtered_events AS+ (SELECT events.event AS event,+ events.properties AS properties,+ toTimeZone(events.timestamp, 'UTC') AS timestamp,+ if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,+ events.`$group_1` AS `$group_1`,+ accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_issue_id'), ''), 'null'), '^"|"$', ''), 'UUID') AS event_issue_id,+ events__fingerprint_issue_state.issue_id AS issue_id,+ events__fingerprint_issue_state.issue_id AS issue_id_v2,+ events__fingerprint_issue_state.issue_name AS issue_name,+ events__fingerprint_issue_state.issue_description AS issue_description,+ events__fingerprint_issue_state.issue_status AS issue_status,+ events__fingerprint_issue_state.assigned_user_id AS issue_assigned_user_id,+ events__fingerprint_issue_state.assigned_role_id AS issue_assigned_role_id,+ events__fingerprint_issue_state.first_seen AS issue_first_seen+ FROM events+ LEFT OUTER JOIN+ (SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_id), error_tracking_fingerprint_issue_state.version), 1)) AS issue_id,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_name), error_tracking_fingerprint_issue_state.version), 1)) AS issue_name,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_description), error_tracking_fingerprint_issue_state.version), 1)) AS issue_description,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_status), error_tracking_fingerprint_issue_state.version), 1)) AS issue_status,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_user_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_user_id,+ toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_role_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_role_id,+ toNullable(tupleElement(argMax(tuple(toTimeZone(error_tracking_fingerprint_issue_state.first_seen, 'UTC')), error_tracking_fingerprint_issue_state.version), 1)) AS first_seen+ FROM error_tracking_fingerprint_issue_state+ WHERE equals(error_tracking_fingerprint_issue_state.team_id, 99999)+ GROUP BY fp_hash+ HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), events__fingerprint_issue_state.fp_hash)+ LEFT OUTER JOIN+ (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,+ person_distinct_id_overrides.distinct_id AS distinct_id+ FROM person_distinct_id_overrides+ WHERE equals(person_distinct_id_overrides.team_id, 99999)+ GROUP BY person_distinct_id_overrides.distinct_id+ HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)+ WHERE and(equals(events.team_id, 99999), equals(events.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), less(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))), notIn(events.event, tuple('paid', 'user signed up')), in(events.event, tuple('positively_related', 'negatively_related')))),+ 2 AS target_step+ SELECT if(ifNull(equals((prop).1, 'Total_Values_In_Query'), 0), 'Total_Values_In_Query', concat(ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), ''), '::', ifNull(toString((prop).3), ''))) AS name,+ countDistinctIf(actor_id, ifNull(equals(steps, target_step), isNull(steps)+ and isNull(target_step))) AS success_count,+ countDistinctIf(actor_id, ifNull(notEquals(steps, target_step), isNotNull(steps)+ or isNotNull(target_step))) AS failure_count+ FROM+ (SELECT funnel_actors.actor_id AS actor_id,+ funnel_actors.steps AS steps,+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '', '')], if(empty(event_table.event), [], arrayMap(prop -> tuple(event_table.event, prop.1, prop.2), JSONExtractKeysAndValues(event_table.properties, 'String'))))) AS prop+ FROM filtered_events AS event_table+ RIGHT JOIN funnel_actors ON and(equals(funnel_actors.actor_id, event_table.`$group_1`), greater(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))))))+ GROUP BY name,+ prop+ HAVING or(equals(name, 'Total_Values_In_Query'), greater(plus(success_count, failure_count), 2))+ LIMIT 100 SETTINGS readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups+ '''+ WITH funnel_actors AS MATERIALIZED+ (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps+ FROM+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target+ FROM+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))+ GROUP BY aggregation_target+ HAVING ifNull(greaterOrEquals(step_reached, 0), 0))+ WHERE bitTest(steps_bitfield, 0)+ ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names+ SELECT event.event AS name,+ countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step))) AS success_count,+ countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step))) AS failure_count+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))+ GROUP BY name+ LIMIT 100+ UNION ALL+ SELECT 'Total_Values_In_Query' AS name,+ countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step))) AS success_count,+ countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step))) AS failure_count+ FROM funnel_actors+ LIMIT 100 SETTINGS readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0+ '''+# ---+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.1+ '''+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -667,66 +754,51 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,optimize_rewrite_aggregate_function_with_if=0,optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties[new_events_schema.2]+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.2'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -751,44 +823,31 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASCLIMIT 101OFFSET 0 SETTINGS optimize_aggregation_in_order=1,join_algorithm='auto',@@ -806,11 +865,9 @@use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties[new_events_schema.3]+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.3'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -835,44 +892,31 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASCLIMIT 101OFFSET 0 SETTINGS optimize_aggregation_in_order=1,join_algorithm='auto',@@ -890,11 +934,9 @@use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties[new_events_schema.4]+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.4'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -919,44 +961,31 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(equals(step_0, 1), equals(step_1, 1))))+ FROM events AS e+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASCLIMIT 101OFFSET 0 SETTINGS optimize_aggregation_in_order=1,join_algorithm='auto',@@ -974,213 +1003,40 @@use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties[new_events_schema]+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.5'''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps+ WITH funnel_actors AS MATERIALIZED+ (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS stepsFROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target+ (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_targetFROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))+ (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1+ FROM events AS e+ LEFT JOIN+ (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry, groups.group_type_index AS index, groups.group_key AS key+ FROM groups+ WHERE and(equals(groups.team_id, 99999), equals(index, 0))+ GROUP BY groups.group_type_index, groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['$browser'], [JSONExtractString(persons.person_props, '$browser')]))) AS prop- FROM funnel_actors- JOIN- (SELECT persons.id AS id,- persons.properties AS person_props- FROM- (SELECT person.id AS id,- person.properties AS properties- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayZip(['$browser'], [JSONExtractString(persons.person_props, '$browser')])) AS prop- FROM funnel_actors- JOIN- (SELECT persons.id AS id,- persons.properties AS person_props- FROM- (SELECT person.id AS id,- person.properties AS properties- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names+ SELECT event.event AS name,+ countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step))) AS success_count,+ countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step))) AS failure_count+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))+ GROUP BY nameLIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up'))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step+ UNION ALLSELECT 'Total_Values_In_Query' AS name,countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)and isNull(target_step))) AS success_count,@@ -1195,15 +1051,15 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.1+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.6'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -1211,17 +1067,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -1234,44 +1084,31 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)+ and isNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASCLIMIT 101OFFSET 0 SETTINGS optimize_aggregation_in_order=1,join_algorithm='auto',@@ -1283,37 +1120,15 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.2- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 0))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.3+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.7'''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events+ SELECT source.actor_id AS actor_idFROM(WITH funnel_actors AS(SELECT aggregation_target AS actor_id,@@ -1321,17 +1136,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -1344,4695 +1153,60 @@aggregation_target AS aggregation_targetFROM(SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,+ e.`$group_0` AS aggregation_target,e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.4- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 0))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.5- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.6- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 0))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.7- '''- SELECT source.id,- source.id AS id,- source.matching_events AS matching_events- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser`- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('today', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS id- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_basic_funnel_correlation_with_properties_materialized.8- '''- SELECT session_replay_events.session_id AS session_id,- min(toTimeZone(session_replay_events.min_first_timestamp, 'UTC')) AS start_time,- max(session_replay_events.retention_period_days) AS retention_period_days,- plus(dateTrunc('DAY', start_time), toIntervalDay(coalesce(retention_period_days, 30))) AS expiry_time- FROM session_replay_events- WHERE and(equals(session_replay_events.team_id, 99999), in(session_replay_events.session_id, ['']))- GROUP BY session_replay_events.session_id- HAVING and(ifNull(greaterOrEquals(expiry_time, toDateTime64('today', 6, 'UTC')), 0), ifNull(equals(max(session_replay_events.is_deleted), 0), 0))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_event_properties_and_groups- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_1` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- filtered_events AS- (SELECT events.event AS event,- events.properties AS properties,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- events.`$group_1` AS `$group_1`,- accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_issue_id'), ''), 'null'), '^"|"$', ''), 'UUID') AS event_issue_id,- events__fingerprint_issue_state.issue_id AS issue_id,- events__fingerprint_issue_state.issue_id AS issue_id_v2,- events__fingerprint_issue_state.issue_name AS issue_name,- events__fingerprint_issue_state.issue_description AS issue_description,- events__fingerprint_issue_state.issue_status AS issue_status,- events__fingerprint_issue_state.assigned_user_id AS issue_assigned_user_id,- events__fingerprint_issue_state.assigned_role_id AS issue_assigned_role_id,- events__fingerprint_issue_state.first_seen AS issue_first_seen- FROM events- LEFT OUTER JOIN- (SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_id), error_tracking_fingerprint_issue_state.version), 1)) AS issue_id,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_name), error_tracking_fingerprint_issue_state.version), 1)) AS issue_name,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_description), error_tracking_fingerprint_issue_state.version), 1)) AS issue_description,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_status), error_tracking_fingerprint_issue_state.version), 1)) AS issue_status,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_user_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_user_id,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_role_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_role_id,- toNullable(tupleElement(argMax(tuple(toTimeZone(error_tracking_fingerprint_issue_state.first_seen, 'UTC')), error_tracking_fingerprint_issue_state.version), 1)) AS first_seen- FROM error_tracking_fingerprint_issue_state- WHERE equals(error_tracking_fingerprint_issue_state.team_id, 99999)- GROUP BY fp_hash- HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__fingerprint_issue_state ON equals(cityHash64(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), events__fingerprint_issue_state.fp_hash)- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), equals(events.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), less(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))), notIn(events.event, tuple('paid', 'user signed up')), in(events.event, tuple('positively_related', 'negatively_related')))),- 2 AS target_step- SELECT if(ifNull(equals((prop).1, 'Total_Values_In_Query'), 0), 'Total_Values_In_Query', concat(ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), ''), '::', ifNull(toString((prop).3), ''))) AS name,- countDistinctIf(actor_id, ifNull(equals(steps, target_step), isNull(steps)- and isNull(target_step))) AS success_count,- countDistinctIf(actor_id, ifNull(notEquals(steps, target_step), isNotNull(steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '', '')], if(empty(event_table.event), [], arrayMap(prop -> tuple(event_table.event, prop.1, prop.2), JSONExtractKeysAndValues(event_table.properties, 'String'))))) AS prop- FROM filtered_events AS event_table- RIGHT JOIN funnel_actors ON and(equals(funnel_actors.actor_id, event_table.`$group_1`), greater(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))))))- GROUP BY name,- prop- HAVING or(equals(name, 'Total_Values_In_Query'), greater(plus(success_count, failure_count), 2))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_event_properties_and_groups[new_events_schema]- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_1` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- filtered_events AS- (SELECT events.event AS event,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> kv.2 != 'null'- AND NOT (kv.2 = '[]'- AND has(['$active_feature_flags', '$exception_functions', '$exception_sources', '$exception_types', '$exception_values'], kv.1)), JSONExtractKeysAndValuesRaw(toJSONString(events.properties)))), ','), '}') AS properties,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id,- events.`$group_1` AS `$group_1`,- accurateCastOrNull(events.properties.`$exception_issue_id`, 'UUID') AS event_issue_id,- events__fingerprint_issue_state.issue_id AS issue_id,- events__fingerprint_issue_state.issue_id AS issue_id_v2,- events__fingerprint_issue_state.issue_name AS issue_name,- events__fingerprint_issue_state.issue_description AS issue_description,- events__fingerprint_issue_state.issue_status AS issue_status,- events__fingerprint_issue_state.assigned_user_id AS issue_assigned_user_id,- events__fingerprint_issue_state.assigned_role_id AS issue_assigned_role_id,- events__fingerprint_issue_state.first_seen AS issue_first_seen- FROM events_json AS events- LEFT OUTER JOIN- (SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_id), error_tracking_fingerprint_issue_state.version), 1)) AS issue_id,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_name), error_tracking_fingerprint_issue_state.version), 1)) AS issue_name,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_description), error_tracking_fingerprint_issue_state.version), 1)) AS issue_description,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.issue_status), error_tracking_fingerprint_issue_state.version), 1)) AS issue_status,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_user_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_user_id,- toNullable(tupleElement(argMax(tuple(error_tracking_fingerprint_issue_state.assigned_role_id), error_tracking_fingerprint_issue_state.version), 1)) AS assigned_role_id,- toNullable(tupleElement(argMax(tuple(toTimeZone(error_tracking_fingerprint_issue_state.first_seen, 'UTC')), error_tracking_fingerprint_issue_state.version), 1)) AS first_seen- FROM error_tracking_fingerprint_issue_state- WHERE equals(error_tracking_fingerprint_issue_state.team_id, 99999)- GROUP BY fp_hash- HAVING equals(argMax(error_tracking_fingerprint_issue_state.is_deleted, error_tracking_fingerprint_issue_state.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__fingerprint_issue_state ON equals(cityHash64(events.properties.`$exception_fingerprint`), events__fingerprint_issue_state.fp_hash)- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), equals(events.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), less(toDateTime(toTimeZone(events.timestamp, 'UTC'), 'UTC'), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))), notIn(events.event, tuple('paid', 'user signed up')), in(events.event, tuple('positively_related', 'negatively_related')))),- 2 AS target_step- SELECT if(ifNull(equals((prop).1, 'Total_Values_In_Query'), 0), 'Total_Values_In_Query', concat(ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), ''), '::', ifNull(toString((prop).3), ''))) AS name,- countDistinctIf(actor_id, ifNull(equals(steps, target_step), isNull(steps)- and isNull(target_step))) AS success_count,- countDistinctIf(actor_id, ifNull(notEquals(steps, target_step), isNotNull(steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '', '')], if(empty(event_table.event), [], arrayMap(prop -> tuple(event_table.event, prop.1, prop.2), JSONExtractKeysAndValues(event_table.properties, 'String'))))) AS prop- FROM filtered_events AS event_table- RIGHT JOIN funnel_actors ON and(equals(funnel_actors.actor_id, event_table.`$group_1`), greater(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toTimeZone(toDateTime(toTimeZone(event_table.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC'))))))- GROUP BY name,- prop- HAVING or(equals(name, 'Total_Values_In_Query'), greater(plus(success_count, failure_count), 2))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_event_properties_and_groups_materialized- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_1` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT concat(ifNull(toString(event_name), ''), '::', ifNull(toString((prop).1), ''), '::', ifNull(toString((prop).2), '')) AS name,- countDistinctIf(actor_id, ifNull(equals(steps, target_step), isNull(steps)- and isNull(target_step))) AS success_count,- countDistinctIf(actor_id, ifNull(notEquals(steps, target_step), isNotNull(steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- event.event AS event_name,- arrayJoin(JSONExtractKeysAndValues(event.properties, 'String')) AS prop- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_1`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), in(event.event, tuple('positively_related', 'negatively_related'))))- GROUP BY name,- prop- HAVING ifNull(greater(plus(success_count, failure_count), 2), 0)- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_1` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups- '''- WITH funnel_actors AS MATERIALIZED- (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.1- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.2- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.3- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.4- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.5- '''- WITH funnel_actors AS MATERIALIZED- (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index, groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.6- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups.7- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.1]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.2]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.3]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.4]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.5]- '''- WITH funnel_actors AS MATERIALIZED- (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry, groups.group_type_index AS index, groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index, groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.6]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema.7]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups[new_events_schema]- '''- WITH funnel_actors AS MATERIALIZED- (SELECT aggregation_target AS actor_id, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, [''] AS prop, arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, af_tuple.5 AS steps_bitfield, aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, e.`$group_0` AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, 'user signed up'), 1, 0) AS step_0, if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events_json AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.1- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.2- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.3- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.4- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.5- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names- SELECT event.event AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), notIn(event.event, []))- GROUP BY name- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'finance'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.6- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_events_and_groups_poe_v2.7- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,- assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,- 2 AS target_step,- ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM events AS event- JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)- WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step)))- GROUP BY actor_id- ORDER BY actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.1- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.2- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.3- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.4- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.5- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema.1]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema.2]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema.3]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema.4]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema.5]- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups[new_events_schema]- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')])) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized.1- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized.2- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized.3- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized.4- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_materialized.5- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(JSONExtractKeysAndValues(groups_0.properties, 'String')) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.1- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.2- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.3- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.4- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.5- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema.1]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema.2]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema.3]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema.4]- '''- SELECT source.actor_id AS actor_id- FROM- (WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- matched_events_array[plus(step_reached, 1)] AS matching_events,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- LEFT JOIN- (SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(groups.group_properties, 'industry'), ''), 'null'), '^"|"$', '')), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties___industry,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE and(equals(groups.team_id, 99999), equals(index, 0))- GROUP BY groups.group_type_index,- groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step SELECT funnel_actors.actor_id AS actor_id,- any(funnel_actors.matching_events) AS matching_events,- actor_id AS key- FROM funnel_actors- WHERE ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))- GROUP BY funnel_actors.actor_id- ORDER BY funnel_actors.actor_id ASC) AS source- ORDER BY source.actor_id ASC- LIMIT 101- OFFSET 0 SETTINGS optimize_aggregation_in_order=1,- join_algorithm='auto',- readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema.5]- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events[new_events_schema]- '''- WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events_json AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)- or isNotNull(target_step))) AS failure_count- FROM- (SELECT funnel_actors.actor_id AS actor_id,- funnel_actors.steps AS steps,- arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS prop- FROM funnel_actors- LEFT JOIN- (SELECT groups.key AS key,- groups.properties AS properties- FROM- (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,- groups.group_type_index AS index,- groups.group_key AS key- FROM groups- WHERE equals(groups.team_id, 99999)- GROUP BY groups.group_type_index,- groups.group_key) AS groups- WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props- GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0+ assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC')) AS date_from,+ assumeNotNull(toDateTime('2020-01-14 23:59:59', 'UTC')) AS date_to,+ 2 AS target_step,+ ['paid', 'user signed up'] AS funnel_step_names SELECT funnel_actors.actor_id AS actor_id,+ any(funnel_actors.matching_events) AS matching_events,+ actor_id AS key+ FROM events AS event+ JOIN funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`)+ WHERE and(equals(event.team_id, 99999), greaterOrEquals(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_from), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), date_to), equals(event.team_id, 99999), greater(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), toTimeZone(funnel_actors.first_timestamp, 'UTC')), less(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), coalesce(toTimeZone(funnel_actors.final_timestamp, 'UTC'), plus(toTimeZone(toTimeZone(funnel_actors.first_timestamp, 'UTC'), 'UTC'), toIntervalDay(14)), date_to)), notIn(event.event, funnel_step_names), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)+ or isNotNull(target_step)))+ GROUP BY actor_id+ ORDER BY actor_id ASC) AS source+ ORDER BY source.actor_id ASC+ LIMIT 101+ OFFSET 0 SETTINGS optimize_aggregation_in_order=1,+ join_algorithm='auto',+ readonly=2,+ max_execution_time=60,+ allow_experimental_object_type=1,+ max_ast_elements=4000000,+ max_expanded_ast_elements=4000000,+ max_bytes_before_external_group_by=0,+ transform_null_in=1,+ optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,+ allow_experimental_join_condition=1,+ use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups'''WITH funnel_actors AS(SELECT aggregation_target AS actor_id,(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6052,13 +1226,13 @@if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -6066,70 +1240,22 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')])) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,groups.properties AS propertiesFROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,+ (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,groups.group_type_index AS index,groups.group_key AS keyFROM groupsWHERE equals(groups.team_id, 99999)GROUP BY groups.group_type_index,groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props+ WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6138,11 +1264,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized.1+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.1'''SELECT source.actor_id AS actor_idFROM@@ -6152,17 +1280,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6190,7 +1312,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6215,11 +1337,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized.2+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.2'''SELECT source.actor_id AS actor_idFROM@@ -6229,17 +1353,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6267,7 +1385,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6292,11 +1410,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized.3+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.3'''SELECT source.actor_id AS actor_idFROM@@ -6306,17 +1426,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6344,7 +1458,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6369,11 +1483,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized.4+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.4'''SELECT source.actor_id AS actor_idFROM@@ -6383,17 +1499,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6421,7 +1531,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6446,28 +1556,24 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_materialized.5+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups.5'''WITH funnel_actors AS(SELECT aggregation_target AS actor_id,(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6487,13 +1593,13 @@if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -6501,70 +1607,22 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(JSONExtractKeysAndValues(groups_0.properties, 'String')) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,groups.properties AS propertiesFROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,+ (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,groups.group_type_index AS index,groups.group_key AS keyFROM groupsWHERE equals(groups.team_id, 99999)GROUP BY groups.group_type_index,groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props+ WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6573,28 +1631,24 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events'''WITH funnel_actors AS(SELECT aggregation_target AS actor_id,(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6614,13 +1668,13 @@if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -6628,70 +1682,22 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')])) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], arrayZip(['industry'], [JSONExtractString(groups_0.properties, 'industry')]))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,groups.properties AS propertiesFROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,+ (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,groups.group_type_index AS index,groups.group_key AS keyFROM groupsWHERE equals(groups.team_id, 99999)GROUP BY groups.group_type_index,groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props+ WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6700,11 +1706,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2.1+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.1'''SELECT source.actor_id AS actor_idFROM@@ -6714,17 +1722,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6752,7 +1754,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6777,11 +1779,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2.2+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.2'''SELECT source.actor_id AS actor_idFROM@@ -6791,17 +1795,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6829,7 +1827,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'positive'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6854,11 +1852,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2.3+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.3'''SELECT source.actor_id AS actor_idFROM@@ -6868,17 +1868,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6906,7 +1900,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -6931,11 +1925,13 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2.4+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.4'''SELECT source.actor_id AS actor_idFROM@@ -6945,17 +1941,11 @@(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -6983,7 +1973,7 @@WHERE and(equals(groups.team_id, 99999), equals(index, 0))GROUP BY groups.group_type_index,groups.group_key) AS e__group_0 ON equals(e.`$group_0`, e__group_0.key)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__group_0.properties___industry, 'negative'), 0), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)@@ -7008,28 +1998,24 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''# ----# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events_poe_v2.5+# name: TestClickhouseFunnelCorrelation.test_funnel_correlation_with_properties_and_groups_person_on_events.5'''WITH funnel_actors AS(SELECT aggregation_target AS actor_id,(matched_events_array[1][1]).1 AS timestamp,nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,(matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp+ steps AS stepsFROM(SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,[''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,+ arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(lessOrEquals(length(x.4), 1), equals(x.4, x_before.4), equals(x.4, x_after.4), equals(x.3, x_before.3), equals(x.3, x_after.3), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,af_tuple.1 AS step_reached,plus(af_tuple.1, 1) AS steps,af_tuple.2 AS breakdown,@@ -7049,13 +2035,13 @@if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'paid'), 1, 0) AS step_1FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))WHERE bitTest(steps_bitfield, 0)ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),2 AS target_step- SELECT concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), '')) AS name,+ SELECT if(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), 'Total_Values_In_Query', concat(ifNull(toString((aggregation_target_with_props.prop).1), ''), '::', ifNull(toString((aggregation_target_with_props.prop).2), ''))) AS name,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(equals(aggregation_target_with_props.steps, target_step), isNull(aggregation_target_with_props.steps)and isNull(target_step))) AS success_count,countDistinctIf(aggregation_target_with_props.actor_id, ifNull(notEquals(aggregation_target_with_props.steps, target_step), isNotNull(aggregation_target_with_props.steps)@@ -7063,70 +2049,22 @@FROM(SELECT funnel_actors.actor_id AS actor_id,funnel_actors.steps AS steps,- arrayJoin(JSONExtractKeysAndValues(groups_0.properties, 'String')) AS prop+ arrayJoin(arrayConcat([tuple('Total_Values_In_Query', '')], JSONExtractKeysAndValues(groups_0.properties, 'String'))) AS propFROM funnel_actorsLEFT JOIN(SELECT groups.key AS key,groups.properties AS propertiesFROM- (SELECT tupleElement(argMax(tuple(groups.group_properties), toTimeZone(groups._timestamp, 'UTC')), 1) AS properties,+ (SELECT argMax(groups.group_properties, toTimeZone(groups._timestamp, 'UTC')) AS properties,groups.group_type_index AS index,groups.group_key AS keyFROM groupsWHERE equals(groups.team_id, 99999)GROUP BY groups.group_type_index,groups.group_key) AS groups- WHERE ifNull(equals(groups.index, 0), 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_props+ WHERE equals(groups.index, 0)) AS groups_0 ON equals(funnel_actors.actor_id, groups_0.key)) AS aggregation_target_with_propsGROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2- HAVING notIn((aggregation_target_with_props.prop).1, [])- LIMIT 100- UNION ALL WITH funnel_actors AS- (SELECT aggregation_target AS actor_id,- (matched_events_array[1][1]).1 AS timestamp,- nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp,- (matched_events_array[1][1]).1 AS first_timestamp,- steps AS steps,- final_timestamp,- first_timestamp- FROM- (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, '', arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array,- [''] AS prop,- arrayJoin(aggregate_funnel(2, 1209600, 'first_touch', 'ordered', prop, [], arrayFilter((x, x_before, x_after) -> not(and(ifNull(lessOrEquals(length(x.4), 1), 0), ifNull(equals(x.4, x_before.4), isNull(x.4)- and isNull(x_before.4)), ifNull(equals(x.4, x_after.4), isNull(x.4)- and isNull(x_after.4)), ifNull(equals(x.3, x_before.3), isNull(x.3)- and isNull(x_before.3)), ifNull(equals(x.3, x_after.3), isNull(x.3)- and isNull(x_after.3)), ifNull(greater(x.1, x_before.1), 0), ifNull(less(x.1, x_after.1), 0))), events_array, arrayRotateRight(events_array, 1), arrayRotateLeft(events_array, 1)))) AS af_tuple,- af_tuple.1 AS step_reached,- plus(af_tuple.1, 1) AS steps,- af_tuple.2 AS breakdown,- af_tuple.3 AS timings,- af_tuple.4 AS matched_event_uuids_array_array,- groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events,- mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map,- arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array,- af_tuple.5 AS steps_bitfield,- aggregation_target AS aggregation_target- FROM- (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp,- e.`$group_0` AS aggregation_target,- e.uuid AS uuid,- e.`$session_id` AS `$session_id`,- e.`$window_id` AS `$window_id`,- if(equals(e.event, 'user signed up'), 1, 0) AS step_0,- if(equals(e.event, 'paid'), 1, 0) AS step_1- FROM events AS e- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), and(notEquals(toString(aggregation_target), ''), isNotNull(aggregation_target))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))- GROUP BY aggregation_target- HAVING ifNull(greaterOrEquals(step_reached, 0), 0))- WHERE bitTest(steps_bitfield, 0)- ORDER BY aggregation_target ASC SETTINGS join_algorithm='auto'),- 2 AS target_step- SELECT 'Total_Values_In_Query' AS name,- countDistinctIf(funnel_actors.actor_id, ifNull(equals(funnel_actors.steps, target_step), isNull(funnel_actors.steps)- and isNull(target_step))) AS success_count,- countDistinctIf(funnel_actors.actor_id, ifNull(notEquals(funnel_actors.steps, target_step), isNotNull(funnel_actors.steps)- or isNotNull(target_step))) AS failure_count- FROM funnel_actors+ HAVING or(equals((aggregation_target_with_props.prop).1, 'Total_Values_In_Query'), notIn((aggregation_target_with_props.prop).1, []))LIMIT 100 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -7135,6 +2073,8 @@max_bytes_before_external_group_by=0,transform_null_in=1,optimize_min_equality_disjunction_chain_length=4294967295,+ optimize_rewrite_aggregate_function_with_if=0,+ optimize_min_inequality_conjunction_chain_length=4294967295,allow_experimental_join_condition=1,use_hive_partitioning=0'''