Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(warehouse_sources): avoid ArrowNotImplementedError on empty composite-PK take (#73011)

Tom Owers1480b322310b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
index d5c53259bbbe..1d55334858ff 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
@@ -164,9 +164,10 @@ def _enrich_cdc_rows(
for j in range(existing_rows.num_rows)
if tuple(arr[j] for arr in ex_pk_arrays) in enrich_key_set
]
- existing_rows = existing_rows.take(match_indices)
+ # Explicit int64 so an empty result doesn't infer a null-typed index array.
+ existing_rows = existing_rows.take(pa.array(match_indices, type=pa.int64()))
else:
- existing_rows = existing_rows.take([])
+ existing_rows = existing_rows.take(pa.array([], type=pa.int64()))
# For SCD2 tables, keep only "current" rows (valid_to IS NULL) so we
# enrich with the most recent state rather than a historical one.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
index a0d6bdaeaa33..5c3da85aa8af 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
@@ -540,6 +540,80 @@ class TestEnrichCdcRows:
assert result.column("big").to_pylist() == ["current-toast"]
+ def test_composite_pk_delete_enrichment_with_no_matching_existing_row(self):
+ # Existing row shares the first PK component ("id") with the incoming DELETE
+ # but not the full composite key, so `match_indices` narrows to empty. This
+ # used to crash with ArrowNotImplementedError: `Table.take([])` infers a
+ # null-typed indices array, and pyarrow has no take kernel for (string, null).
+ with tempfile.TemporaryDirectory() as path:
+ write_deltalake(
+ path,
+ pa.table(
+ {
+ "id": pa.array([1], pa.int64()),
+ "tenant": pa.array(["a"], pa.string()),
+ "name": pa.array(["existing"], pa.string()),
+ }
+ ),
+ mode="overwrite",
+ )
+
+ batch = pa.table(
+ {
+ "id": pa.array([1], pa.int64()),
+ "tenant": pa.array(["z"], pa.string()),
+ "name": pa.array([None], pa.string()),
+ CDC_OP_COLUMN: pa.array(["D"], pa.string()),
+ TOAST_OMITTED_COLUMN: pa.array([None], pa.list_(pa.string())),
+ }
+ )
+ result = _enrich_cdc_rows(
+ batch,
+ primary_keys=["id", "tenant"],
+ cdc_write_mode="incremental_merge",
+ existing_delta_table=DeltaTable(path),
+ batch_index=0,
+ )
+
+ assert TOAST_OMITTED_COLUMN not in result.column_names
+ assert result.column("name").to_pylist() == [None]
+
+ def test_composite_pk_delete_enrichment_when_existing_table_lacks_a_pk_column(self):
+ # The existing Delta table predates a composite key gaining a second PK
+ # column ("tenant"), so it can't be exactly matched. Same bug as above but
+ # via the `else` branch, which also called `.take([])` unconditionally.
+ with tempfile.TemporaryDirectory() as path:
+ write_deltalake(
+ path,
+ pa.table(
+ {
+ "id": pa.array([1], pa.int64()),
+ "name": pa.array(["existing"], pa.string()),
+ }
+ ),
+ mode="overwrite",
+ )
+
+ batch = pa.table(
+ {
+ "id": pa.array([1], pa.int64()),
+ "tenant": pa.array(["z"], pa.string()),
+ "name": pa.array([None], pa.string()),
+ CDC_OP_COLUMN: pa.array(["D"], pa.string()),
+ TOAST_OMITTED_COLUMN: pa.array([None], pa.list_(pa.string())),
+ }
+ )
+ result = _enrich_cdc_rows(
+ batch,
+ primary_keys=["id", "tenant"],
+ cdc_write_mode="incremental_merge",
+ existing_delta_table=DeltaTable(path),
+ batch_index=0,
+ )
+
+ assert TOAST_OMITTED_COLUMN not in result.column_names
+ assert result.column("name").to_pylist() == [None]
+
def test_marker_dropped_when_enrichment_cannot_run(self):
# First-ever CDC batch: no existing Delta table to fill from. The value is
# unknowable (stays null) but the transport marker must never reach the write.