: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): register binary Arrow columns in HogQLSchema (#75931)
Tom Owersef94f9ccbe5c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/hogql_schema.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/hogql_schema.pyindex 8f953bc6ca21..33146ad504fe 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/hogql_schema.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/hogql_schema.py@@ -35,9 +35,6 @@ class HogQLSchema:if existing_type is not None and existing_type != StringDatabaseField.__name__:continue- if pa.types.is_binary(field.type):- continue-self.schema[field.name] = self._map_arrow_type(field.type).__name__def add_field(self, field: pa.Field, column: pa.ChunkedArray) -> None:@@ -45,9 +42,6 @@ class HogQLSchema:if existing_type is not None and existing_type != StringDatabaseField.__name__:return- if pa.types.is_binary(field.type):- return-hogql_type = self._map_arrow_type(field.type)if hogql_type is StringDatabaseField:@@ -84,6 +78,11 @@ class HogQLSchema:return IntegerDatabaseFieldelif pa.types.is_string(arrow_type):return StringDatabaseField+ elif pa.types.is_binary(arrow_type) or pa.types.is_large_binary(arrow_type):+ # ClickHouse's deltaLake()/Parquet readers surface binary columns as String, so+ # db_columns always reports "String" for these — map to the same HogQL type or+ # merge_columns can never find a match for them.+ return StringDatabaseFieldreturn DatabaseFielddef to_hogql_types(self) -> dict[str, str]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_hogql_schema.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_hogql_schema.pyindex 1ddaf4329496..a0b0c3103027 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_hogql_schema.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_hogql_schema.py@@ -49,6 +49,8 @@ class TestAddPyarrowSchema:("timestamp_us", pa.timestamp("us"), "DateTimeDatabaseField"),("date32", pa.date32(), "DateDatabaseField"),("decimal128", pa.decimal128(10, 2), "FloatDatabaseField"),+ ("binary", pa.binary(), "StringDatabaseField"),+ ("large_binary", pa.large_binary(), "StringDatabaseField"),])def test_maps_arrow_type(self, _name: str, arrow_type: pa.DataType, expected: str):@@ -57,13 +59,6 @@ class TestAddPyarrowSchema:schema.add_pyarrow_schema(pa.schema(fields))assert schema.schema["col"] == expected- def test_skips_binary_fields(self):- arrow_schema = pa.schema([pa.field("bin_col", pa.binary())])- schema = HogQLSchema()- schema.add_pyarrow_schema(arrow_schema)-- assert "bin_col" not in schema.schema-def test_does_not_overwrite_non_string_types(self):schema = HogQLSchema()table = pa.table({"col": pa.array([1, 2], type=pa.int64())})@@ -192,3 +187,16 @@ class TestMergeColumnsRaceCondition:assert "user_id" in resultassert "new_col" not in result++ def test_merge_columns_keeps_binary_column_registered_by_hogql_schema(self):+ # A binary Arrow column (e.g. a BigQuery BYTES field) is read back by ClickHouse's+ # deltaLake() reader as String, so HogQLSchema must register a type for it or this+ # column is dropped from `columns` on every sync.+ table = pa.table({"key": pa.array([b"abc"], type=pa.binary())})+ schema = HogQLSchema()+ schema.add_pyarrow_table(table)++ db_columns = {"key": "String"}+ result = merge_columns(db_columns, schema.to_hogql_types(), {})++ assert result["key"] == {"clickhouse": "String", "hogql": "StringDatabaseField"}