: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(data-imports): return clean error when a direct source has no config (#90539)
Tom Owersbf3fa70723b0
diff --git a/posthog/hogql/direct_sql/adapter.py b/posthog/hogql/direct_sql/adapter.pyindex bd25f0850c7d..06f76db0df1d 100644--- a/posthog/hogql/direct_sql/adapter.py+++ b/posthog/hogql/direct_sql/adapter.py@@ -1,8 +1,9 @@import dataclassesfrom dataclasses import field-from typing import TYPE_CHECKING, Any, Protocol+from typing import TYPE_CHECKING, Any, Protocol, TypeVarfrom posthog.hogql.constants import HogQLDialect, HogQLGlobalSettings+from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.hogql.timings import HogQLTimingsif TYPE_CHECKING:@@ -12,6 +13,26 @@ if TYPE_CHECKING:from posthog.dataclasses import frozen+_ConfigT_co = TypeVar("_ConfigT_co", covariant=True)+++class _ParseableSource(Protocol[_ConfigT_co]):+ def parse_config(self, job_inputs: dict) -> _ConfigT_co: ...+++def parse_direct_source_config(source_impl: _ParseableSource[_ConfigT_co], source: "ExternalDataSource") -> _ConfigT_co:+ """Build a source's connection config from its stored ``job_inputs``.++ A direct-capable source can reach a live query with empty or incomplete ``job_inputs``+ (credentials never finished setup, were cleared, or can't be decrypted). Config building then+ raises a raw ``TypeError``/``ValueError`` that would otherwise leak to error tracking; convert+ it to a clean user-facing error instead.+ """+ try:+ return source_impl.parse_config(source.job_inputs or {})+ except (TypeError, ValueError) as error:+ raise ExposedHogQLError("This source is missing its connection configuration.") from error+@frozenclass DirectQueryPrincipal:diff --git a/posthog/hogql/direct_sql/clickhouse_adapter.py b/posthog/hogql/direct_sql/clickhouse_adapter.pyindex 4d56381f3b4a..441f94a66737 100644--- a/posthog/hogql/direct_sql/clickhouse_adapter.py+++ b/posthog/hogql/direct_sql/clickhouse_adapter.py@@ -10,7 +10,7 @@ from sshtunnel import BaseSSHTunnelForwarderErrorfrom posthog.hogql.constants import HogQLDialectfrom posthog.hogql.direct_query_metrics import DIRECT_QUERY_ROW_CAP_EXCEEDED_TOTAL, observe_direct_query-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statementfrom posthog.hogql.errors import ExposedHogQLError@@ -259,7 +259,7 @@ class ClickHouseAdapter:else ExternalDataSourceType.CLICKHOUSE)clickhouse_source = cast("ClickHouseSource", SourceRegistry.get_source(source_type))- config = clickhouse_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(clickhouse_source, source)is_ssh_valid, ssh_valid_errors = clickhouse_source.ssh_tunnel_is_valid(config, team.pk)if not is_ssh_valid:diff --git a/posthog/hogql/direct_sql/motherduck_adapter.py b/posthog/hogql/direct_sql/motherduck_adapter.pyindex 513a59e2c4cd..6f3f348aa50b 100644--- a/posthog/hogql/direct_sql/motherduck_adapter.py+++ b/posthog/hogql/direct_sql/motherduck_adapter.py@@ -11,7 +11,7 @@ from sqlparse.sql import Tokenfrom posthog.hogql.constants import HogQLDialectfrom posthog.hogql.direct_query_metrics import DIRECT_QUERY_ROW_CAP_EXCEEDED_TOTAL, observe_direct_query-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statementfrom posthog.hogql.errors import ExposedHogQLError@@ -212,7 +212,7 @@ class MotherDuckAdapter:raise ExposedHogQLError("Invalid direct MotherDuck connection.")motherduck_source = cast("MotherduckSource", SourceRegistry.get_source(ExternalDataSourceType.MOTHERDUCK))- config = motherduck_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(motherduck_source, source)# No host/SSH-tunnel config to validate: the driver always dials MotherDuck's fixed# SaaS endpoint, so there is no SSRF surface equivalent to the Postgres/MySQL hosts.diff --git a/posthog/hogql/direct_sql/mysql_adapter.py b/posthog/hogql/direct_sql/mysql_adapter.pyindex 32c84d86eff2..77486f620717 100644--- a/posthog/hogql/direct_sql/mysql_adapter.py+++ b/posthog/hogql/direct_sql/mysql_adapter.py@@ -9,7 +9,7 @@ from sqlparse.sql import Statementfrom sshtunnel import BaseSSHTunnelForwarderErrorfrom posthog.hogql.constants import HogQLDialect-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statementfrom posthog.hogql.errors import ExposedHogQLError@@ -131,7 +131,7 @@ class MySQLAdapter:raise ExposedHogQLError("Invalid direct MySQL connection.")mysql_source = cast(MySQLSource, SourceRegistry.get_source(ExternalDataSourceType.MYSQL))- config = mysql_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(mysql_source, source)is_ssh_valid, ssh_valid_errors = mysql_source.ssh_tunnel_is_valid(config, team.pk)if not is_ssh_valid:diff --git a/posthog/hogql/direct_sql/postgres_adapter.py b/posthog/hogql/direct_sql/postgres_adapter.pyindex f83d957e73a4..fbdbeb2ed4da 100644--- a/posthog/hogql/direct_sql/postgres_adapter.py+++ b/posthog/hogql/direct_sql/postgres_adapter.py@@ -6,7 +6,7 @@ from opentelemetry import tracefrom sshtunnel import BaseSSHTunnelForwarderErrorfrom posthog.hogql.constants import HogQLDialect-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.pgwire import (MANAGED_WAREHOUSE_CONNECTION_ERROR,@@ -134,7 +134,7 @@ class PostgresAdapter:postgres_source = cast(PostgresSource, SourceRegistry.get_source(ExternalDataSourceType.POSTGRES))with timings.measure("postgres_source_parse_config"):- config = postgres_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(postgres_source, source)with timings.measure("postgres_ssh_validation"):is_ssh_valid, ssh_valid_errors = postgres_source.ssh_tunnel_is_valid(config, team.pk)diff --git a/posthog/hogql/direct_sql/redshift_adapter.py b/posthog/hogql/direct_sql/redshift_adapter.pyindex a90cd3b65753..f1f39272bc50 100644--- a/posthog/hogql/direct_sql/redshift_adapter.py+++ b/posthog/hogql/direct_sql/redshift_adapter.py@@ -8,7 +8,7 @@ from sshtunnel import BaseSSHTunnelForwarderErrorfrom posthog.hogql.constants import HogQLDialectfrom posthog.hogql.direct_query_metrics import DIRECT_QUERY_ROW_CAP_EXCEEDED_TOTAL, observe_direct_query-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.pgwire import postgres_error_to_message, postgres_oid_to_clickhouse_typefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statement@@ -112,7 +112,7 @@ class RedshiftAdapter:raise ExposedHogQLError("Invalid direct Redshift connection.")redshift_source = cast(RedshiftSource, SourceRegistry.get_source(ExternalDataSourceType.REDSHIFT))- config = redshift_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(redshift_source, source)is_ssh_valid, ssh_valid_errors = redshift_source.ssh_tunnel_is_valid(config, team.pk)if not is_ssh_valid:diff --git a/posthog/hogql/direct_sql/snowflake_adapter.py b/posthog/hogql/direct_sql/snowflake_adapter.pyindex 2709edbf31c8..47cb6278f497 100644--- a/posthog/hogql/direct_sql/snowflake_adapter.py+++ b/posthog/hogql/direct_sql/snowflake_adapter.py@@ -9,7 +9,7 @@ from sqlparse import tokens as sqlparse_tokensfrom posthog.hogql.constants import HogQLDialectfrom posthog.hogql.direct_query_metrics import DIRECT_QUERY_ROW_CAP_EXCEEDED_TOTAL, observe_direct_query-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statementfrom posthog.hogql.errors import ExposedHogQLError@@ -170,7 +170,7 @@ class SnowflakeAdapter:raise ExposedHogQLError("Invalid direct Snowflake connection.")snowflake_source = cast(SnowflakeSource, SourceRegistry.get_source(ExternalDataSourceType.SNOWFLAKE))- config = snowflake_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(snowflake_source, source)# Snowflake has no host/SSH-tunnel config to validate (the Postgres/MySQL SSRF check),# but the account identifier flows into the host the connector dials, so it gets thediff --git a/posthog/hogql/direct_sql/trino_adapter.py b/posthog/hogql/direct_sql/trino_adapter.pyindex a04a560183a5..6d2adb70e457 100644--- a/posthog/hogql/direct_sql/trino_adapter.py+++ b/posthog/hogql/direct_sql/trino_adapter.py@@ -9,7 +9,7 @@ from sqlparse import tokens as sqlparse_tokensfrom posthog.hogql.constants import HogQLDialectfrom posthog.hogql.direct_query_metrics import DIRECT_QUERY_ROW_CAP_EXCEEDED_TOTAL, observe_direct_query-from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult+from posthog.hogql.direct_sql.adapter import DirectQueryRequest, DirectQueryResult, parse_direct_source_configfrom posthog.hogql.direct_sql.capability import is_direct_capablefrom posthog.hogql.direct_sql.raw_sql import ensure_single_direct_statementfrom posthog.hogql.errors import ExposedHogQLError@@ -86,7 +86,7 @@ class TrinoAdapter:raise ExposedHogQLError("Invalid direct Trino connection.")trino_source = cast("TrinoSource", SourceRegistry.get_source(ExternalDataSourceType.TRINO))- config = trino_source.parse_config(source.job_inputs or {})+ config = parse_direct_source_config(trino_source, source)is_valid, error = trino_source.is_database_host_valid(config.host, team.pk)if not is_valid:raise ExposedHogQLError(error or "Invalid Trino host.")diff --git a/posthog/hogql/test/test_direct_postgres_query.py b/posthog/hogql/test/test_direct_postgres_query.pyindex 06ac1aa6ae8c..f8a876438f72 100644--- a/posthog/hogql/test/test_direct_postgres_query.py+++ b/posthog/hogql/test/test_direct_postgres_query.py@@ -22,6 +22,7 @@ from posthog.hogql.direct_sql.pgwire import (postgres_oid_to_clickhouse_type,)from posthog.hogql.direct_sql.postgres_adapter import (+ PostgresAdapter,direct_postgres_session_setup_sql,get_runtime_direct_postgres_connection_metadata,)@@ -2051,3 +2052,26 @@ class TestDirectPostgresQuery(APIBaseTest):self.assertIn("Invalid connectionId", str(ctx.exception))mock_connect.assert_not_called()++ @parameterized.expand(+ [+ ("empty", {}),+ ("partial", {"host": "localhost", "schema": "public"}),+ ]+ )+ def test_validate_source_config_raises_exposed_error_for_incomplete_job_inputs(self, _name: str, job_inputs: dict):+ # A direct-capable Postgres source with missing connection credentials must surface a clean+ # ExposedHogQLError, not a raw TypeError from config building that leaks to error tracking.+ source = ExternalDataSource.objects.create(+ team=self.team,+ source_id="source_id",+ connection_id="connection_id",+ status=ExternalDataSource.Status.COMPLETED,+ source_type="Postgres",+ access_method=ExternalDataSource.AccessMethod.DIRECT,+ prefix="ph3",+ job_inputs=job_inputs,+ )++ with self.assertRaises(ExposedHogQLError):+ PostgresAdapter().validate_source_config(source, self.team)diff --git a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambrindex 017f23c3892b..17d46f5c097e 100644--- a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr+++ b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr@@ -34,7 +34,7 @@e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'user did things'), 1, 0) AS step_1,- ([e__person.properties___fish] AS value) AS prop_basic,+ ([replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', '')] AS value) AS prop_basic,prop_basic AS propFROM events AS eLEFT OUTER JOIN@@ -44,16 +44,6 @@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 person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- 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('user did things', 'user signed up')), ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -121,17 +111,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)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- 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('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 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, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -188,8 +168,8 @@e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_0,- if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_1+ if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 1, 0) AS step_0,+ if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 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,@@ -198,16 +178,6 @@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 person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- 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('user did things', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -324,24 +294,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM 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, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- 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), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -373,24 +326,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM 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, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- 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), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)