: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
perf(data-warehouse): open a delta table without a separate existence check (#113086)
Tom Owers630851d5f645
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/source_manager.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/source_manager.pyindex 000cee792348..ae2b560676e1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/source_manager.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/source_manager.py@@ -375,7 +375,9 @@ async def build_output_lanes(lanes: list[OutputLane] = []positions: list[int | None] = []for index, lane in enumerate(served_lanes(schema)):- delta_table = await DeltaTableRef(lane.resource_name, job, logger).get_delta_table()+ delta_table = await DeltaTableRef(+ lane.resource_name, job, logger, expect_missing=schema.table_id is None+ ).get_delta_table()is_append = lane.write_mode == COMPANION_WRITE_MODEkeys = [normalize_column_name(name) for name in schema.primary_key_columns or []]if delta_table is not None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/scd2.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/scd2.pyindex 342abab957ea..26b7123ffbcb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/scd2.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/scd2.py@@ -130,6 +130,7 @@ class Scd2DeltaWriter:storage_options=storage_options,configuration=DELTA_TABLE_PROPERTIES,)+ self._table.adopt_created_table(delta_table)await asyncio.to_thread(deltalake.write_deltalake,diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.pyindex 593feabc71b0..26f201d2ba8b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/table.py@@ -213,9 +213,19 @@ class DeltaTableRef:#: The newest version deltalite reported committing through this ref, if any._deltalite_version: int | None_table_uri: str | None+ #: A hint that the next open will find no table. It only selects which request goes first.+ _expect_missing: bool+ #: True from an open that found no table until this ref creates, resets or invalidates it.+ _known_missing: booldef __init__(- self, resource_name: str, job: ExternalDataJob, logger: FilteringBoundLogger, is_first_sync: bool = False+ self,+ resource_name: str,+ job: ExternalDataJob,+ logger: FilteringBoundLogger,+ is_first_sync: bool = False,+ *,+ expect_missing: bool | None = None,) -> None:self._resource_name = resource_nameself._job = job@@ -225,6 +235,8 @@ class DeltaTableRef:self._cached_table_stale = Falseself._deltalite_version = Noneself._table_uri = None+ self._expect_missing = is_first_sync if expect_missing is None else expect_missing+ self._known_missing = False@propertydef is_first_sync(self) -> bool:@@ -296,14 +308,20 @@ class DeltaTableRef:raise TransientObjectStoreError(str(e)) from ecapture_exception(e)- async def get_delta_table(self, *, allow_stale: bool = False) -> deltalake.DeltaTable | None:+ async def get_delta_table(+ self, *, allow_stale: bool = False, allow_known_missing: bool = False+ ) -> deltalake.DeltaTable | None:"""Open the table once and hand back the same handle for the rest of this ref's life.The cache is per instance on purpose. A process-wide slot lets any other table in flight onthe same worker evict this one's handle, and every re-open is a full Delta-log replay againstobject storage. Writes through the handle keep it current, so it stays valid until this ref's- own `invalidate_cached_table` (reset, repartition swap) says otherwise. A missing table is- never cached, so a table created after the first probe is found by the next call.+ own `invalidate_cached_table` (reset, repartition swap) says otherwise.++ A missing table is looked for again on each call, so a table that another writer created+ after the first probe is found. `allow_known_missing` skips that second look. It is only for+ a caller whose result does not depend on the answer: a write that overwrites the table,+ which creates the table itself when the answer is None (see `adopt_created_table`).A deltalite write commits past this handle (see `note_deltalite_commit`), after which thecached snapshot is behind the log by that commit: same table id, same columns, same@@ -316,11 +334,25 @@ class DeltaTableRef:if self._cached_table_stale and not allow_stale:await self._refresh_cached_table(self._cached_table)return self._cached_table+ if allow_known_missing and self._known_missing:+ return Nonetable = await self._open_delta_table()self._cached_table = tableself._cached_table_stale = False+ self._known_missing = table is Nonereturn table+ def adopt_created_table(self, table: deltalake.DeltaTable) -> None:+ """Keep the handle of a table that the caller just created at this ref's URI.++ A new table has no log to replay, so the handle from the create call is the same snapshot+ that a new open gives. The writes that follow go through it and keep it current.+ """+ self._cached_table = table+ self._cached_table_stale = False+ self._known_missing = False+ self._expect_missing = False+async def _refresh_cached_table(self, table: deltalake.DeltaTable) -> None:try:await asyncio.to_thread(table.update_incremental)@@ -369,11 +401,35 @@ class DeltaTableRef:self._cached_table = Noneself._cached_table_stale = Falseself._deltalite_version = None+ self._known_missing = False++ async def _open_directly(self, delta_uri: str, storage_options: dict[str, str]) -> deltalake.DeltaTable | None:+ """Open the table with no existence check first, or None when that open fails.++ A table that opens always has a commit or a checkpoint in its log, which is what+ `is_deltatable` looks for, so a successful open needs no second answer. A failed open says+ nothing here: the caller runs the existence check and the open again, in that order, and+ classifies the error from that second attempt. Thus a missing table, a prefix that is not a+ table, a damaged log and a refused request all get the same handling as before.++ Skipped when the table is expected to be missing, because the existence check alone is then+ the cheaper first request.+ """+ if self._expect_missing:+ return None+ try:+ return await asyncio.to_thread(deltalake.DeltaTable, table_uri=delta_uri, storage_options=storage_options)+ except Exception:+ return Noneasync def _open_delta_table(self) -> deltalake.DeltaTable | None:delta_uri = await self._get_delta_table_uri()storage_options = self._get_credentials()+ table = await self._open_directly(delta_uri, storage_options)+ if table is not None:+ return table+try:is_delta = await asyncio.to_thread(deltalake.DeltaTable.is_deltatable, table_uri=delta_uri, storage_options=storage_options@@ -420,6 +476,7 @@ class DeltaTableRef:raiseself._is_first_sync = True+ self._expect_missing = Truereturn None@@ -437,6 +494,9 @@ class DeltaTableRef:delta_uri = await self._get_delta_table_uri()storage_options = self._get_credentials()+ if await self._open_directly(delta_uri, storage_options) is not None:+ return False+is_delta = await asyncio.to_thread(deltalake.DeltaTable.is_deltatable, table_uri=delta_uri, storage_options=storage_options)@@ -469,6 +529,7 @@ class DeltaTableRef:await self._logger.adebug("reset_table: _is_first_sync=True")self._is_first_sync = True+ self._expect_missing = Trueasync def get_file_uris(self) -> list[str]:delta_table = await self.get_delta_table()diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_scd2.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_scd2.pyindex 8e2290cf328c..1e05e2b5262b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_scd2.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_scd2.py@@ -37,9 +37,14 @@ class TestScd2Write:})- await _make_writer(delta_path).write(data=batch, primary_keys=["id"])-- assert deltalake.DeltaTable(delta_path).metadata().configuration.get("delta.checkpointInterval") == "25"+ writer = _make_writer(delta_path)+ written = await writer.write(data=batch, primary_keys=["id"])++ live = deltalake.DeltaTable(delta_path)+ assert live.metadata().configuration.get("delta.checkpointInterval") == "25"+ # The ref keeps the handle of the table it created, and that handle holds every commit of the write.+ assert await writer._table.get_delta_table() is written+ assert written.version() == live.version()@pytest.mark.asyncioasync def test_write_misaligned_decimal_to_local_delta(self, tmp_path: Path) -> None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.pyindex 79786ec7647d..b7ef308d8fe6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_table.py@@ -1,4 +1,5 @@import json+import tempfilefrom collections.abc import Callablefrom pathlib import Pathfrom typing import cast@@ -171,6 +172,181 @@ class TestGetDeltaTableCache:mock_delta_table.assert_not_called()+def _no_table(path: Path) -> None:+ pass+++def _data_file_only(path: Path) -> None:+ path.mkdir(parents=True)+ pq.write_table(pa.table({"id": [1]}), path / "part-0.parquet")+++def _stray_log_file(path: Path) -> None:+ (path / "_delta_log").mkdir(parents=True)+ (path / "_delta_log" / "_commit_0.json.tmp").write_text("{}")+++def _checkpoint_hint_only(path: Path) -> None:+ (path / "_delta_log").mkdir(parents=True)+ (path / "_delta_log" / "_last_checkpoint").write_text('{"version": 5, "size": 10}')+++def _commit_without_metadata(path: Path) -> None:+ (path / "_delta_log").mkdir(parents=True)+ (path / "_delta_log" / "00000000000000000000.json").write_text('{"commitInfo": {"timestamp": 1}}\n')+++def _files_under(path: Path) -> set[str]:+ return {str(file.relative_to(path)) for file in path.rglob("*") if file.is_file()}+++class TestOpenWithoutExistenceCheck:+ _MODULE = "products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table"++ @parameterized.expand(+ [+ # (name, expect_missing, table_exists, existence_checks, opens)+ ("existing_table_opens_with_no_check", False, True, 0, 1),+ ("expected_missing_table_costs_one_check", True, False, 1, 0),+ ("unexpected_missing_table_falls_back_to_the_check", False, False, 1, 1),+ ("expected_missing_but_present_checks_then_opens", True, True, 1, 1),+ ]+ )+ @pytest.mark.asyncio+ async def test_object_store_calls_for_one_open(+ self, _name: str, expect_missing: bool, table_exists: bool, existence_checks: int, opens: int+ ) -> None:+ ref = DeltaTableRef("t", MagicMock(), make_logger(), expect_missing=expect_missing)+ handle = MagicMock()++ with (+ patch.object(ref, "_get_delta_table_uri", AsyncMock(return_value="s3://bucket/team/job/t")),+ patch.object(ref, "_get_credentials", MagicMock(return_value={})),+ patch(f"{self._MODULE}.deltalake.DeltaTable") as mock_delta_table,+ ):+ mock_delta_table.is_deltatable.return_value = table_exists+ if table_exists:+ mock_delta_table.return_value = handle+ else:+ mock_delta_table.side_effect = deltalake.exceptions.TableNotFoundError(+ "Generic delta kernel error: No files in log segment"+ )++ table = await ref.get_delta_table()++ assert table is (handle if table_exists else None)+ assert ref.is_first_sync is not table_exists+ assert mock_delta_table.is_deltatable.call_count == existence_checks+ assert mock_delta_table.call_count == opens++ @parameterized.expand(+ [+ (f"{layout.__name__.strip('_')}_{'expected' if expect_missing else 'unexpected'}", layout, expect_missing)+ for layout in (_no_table, _data_file_only, _stray_log_file, _checkpoint_hint_only)+ for expect_missing in (False, True)+ ]+ )+ @pytest.mark.asyncio+ async def test_a_prefix_that_holds_no_table_reads_as_no_table_and_keeps_its_files(+ self, _name: str, layout: Callable[[Path], None], expect_missing: bool+ ) -> None:+ with tempfile.TemporaryDirectory() as tmp:+ path = Path(tmp) / "table"+ layout(path)+ before = _files_under(path)+ ref = DeltaTableRef("t", MagicMock(), make_logger(), expect_missing=expect_missing)++ with (+ patch.object(ref, "_get_delta_table_uri", AsyncMock(return_value=str(path))),+ patch.object(ref, "_get_credentials", MagicMock(return_value={})),+ patch(f"{self._MODULE}._purge_s3_prefix", AsyncMock()) as purge,+ ):+ assert await ref.get_delta_table() is None+ assert await ref.is_table_corrupted() is False++ assert ref.is_first_sync is True+ purge.assert_not_awaited()+ assert _files_under(path) == before++ @parameterized.expand([("unexpected", False), ("expected", True)])+ @pytest.mark.asyncio+ async def test_a_log_with_no_metadata_is_still_corrupt_and_still_healed(+ self, _name: str, expect_missing: bool+ ) -> None:+ with tempfile.TemporaryDirectory() as tmp:+ path = Path(tmp) / "table"+ _commit_without_metadata(path)+ ref = DeltaTableRef("t", MagicMock(), make_logger(), expect_missing=expect_missing)+ s3_cm = MagicMock(__aenter__=AsyncMock(return_value=MagicMock()), __aexit__=AsyncMock(return_value=False))++ with (+ patch.object(ref, "_get_delta_table_uri", AsyncMock(return_value=str(path))),+ patch.object(ref, "_get_credentials", MagicMock(return_value={})),+ patch(f"{self._MODULE}.aget_s3_client", MagicMock(return_value=s3_cm)),+ patch(f"{self._MODULE}._purge_s3_prefix", AsyncMock()) as purge,+ patch(f"{self._MODULE}.capture_exception"),+ ):+ assert await ref.is_table_corrupted() is True+ assert await ref.get_delta_table() is None++ purge.assert_awaited_once()++ @pytest.mark.asyncio+ async def test_reset_makes_the_next_open_start_with_the_existence_check(self) -> None:+ ref = DeltaTableRef("t", MagicMock(), make_logger())+ s3_cm = MagicMock(__aenter__=AsyncMock(return_value=MagicMock()), __aexit__=AsyncMock(return_value=False))++ with (+ patch.object(ref, "_get_delta_table_uri", AsyncMock(return_value="s3://bucket/team/job/t")),+ patch.object(ref, "_get_credentials", MagicMock(return_value={})),+ patch(f"{self._MODULE}.aget_s3_client", MagicMock(return_value=s3_cm)),+ patch(f"{self._MODULE}._purge_s3_prefix", AsyncMock()),+ patch(f"{self._MODULE}.deltalake.DeltaTable") as mock_delta_table,+ ):+ mock_delta_table.is_deltatable.return_value = False+ await ref.reset_table()++ assert await ref.get_delta_table() is None++ mock_delta_table.assert_not_called()+ mock_delta_table.is_deltatable.assert_called_once()+++class TestKnownMissingTable:+ @parameterized.expand(+ [+ # (name, allow_known_missing, step between the two reads, probes, second read finds a table)+ ("default_read_looks_again", False, "nothing", 2, False),+ ("allowed_read_reuses_the_answer", True, "nothing", 1, False),+ ("default_read_finds_a_table_another_writer_created", False, "created_elsewhere", 2, True),+ ("adopted_table_is_returned_with_no_probe", True, "adopted", 1, True),+ ("invalidate_forgets_the_answer", True, "invalidated", 2, False),+ ]+ )+ @pytest.mark.asyncio+ async def test_second_read_of_a_missing_table(+ self, _name: str, allow_known_missing: bool, step: str, probes: int, finds_table: bool+ ) -> None:+ with tempfile.TemporaryDirectory() as tmp:+ uri = str(Path(tmp) / "table")+ ref = make_local_table_ref(uri)++ with patch.object(ref, "_open_delta_table", AsyncMock(side_effect=ref._open_delta_table)) as probe:+ assert await ref.get_delta_table() is None++ if step == "created_elsewhere":+ deltalake.write_deltalake(uri, pa.table({"id": [1]}))+ elif step == "adopted":+ ref.adopt_created_table(deltalake.DeltaTable.create(uri, schema=pa.schema([("id", pa.int64())])))+ elif step == "invalidated":+ ref.invalidate_cached_table()++ table = await ref.get_delta_table(allow_known_missing=allow_known_missing)++ assert (table is not None) is finds_table+ assert probe.await_count == probes++class TestStorageOptionsCommitSafety:# Re-adding AWS_S3_ALLOW_UNSAFE_RENAME unconditionally would silently restore# the legacy rename backend, which has no commit-conflict detection.@@ -325,6 +501,7 @@ class TestGetDeltaTableUnrecoverableErrors:patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,patch(f"{module}.capture_exception") as mock_capture,):+ mock_delta_table.side_effect = OSError("unexpected end of stream while reading response")mock_delta_table.is_deltatable.side_effect = OSError("unexpected end of stream while reading response")with pytest.raises(OSError, match="unexpected end of stream"):@@ -355,6 +532,7 @@ class TestGetDeltaTableUnrecoverableErrors:patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,patch(f"{module}.capture_exception") as mock_capture,):+ mock_delta_table.side_effect = original_errormock_delta_table.is_deltatable.side_effect = original_errorwith pytest.raises(TransientObjectStoreError, match="operation timed out") as exc_info:@@ -387,6 +565,7 @@ class TestGetDeltaTableUnrecoverableErrors:patch(f"{module}.deltalake.DeltaTable") as mock_delta_table,patch(f"{module}.capture_exception") as mock_capture,):+ mock_delta_table.side_effect = original_errormock_delta_table.is_deltatable.side_effect = original_errorwith pytest.raises(ObjectStorePermissionDeniedError) as exc_info:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.pyindex 22566b0f5f2c..1c746d69a92e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_writer.py@@ -902,6 +902,65 @@ class TestCreateRaceWithExistingTable:assert set(result.to_pyarrow_table().column("id").to_pylist()) == expected_ids+class TestFirstBatchOnAMissingTable:+ @pytest.mark.parametrize("write_type", ["full_refresh", "append", "incremental"])+ @pytest.mark.asyncio+ async def test_first_batch_probes_once_and_later_reads_see_each_commit(+ self, write_type: Literal["incremental", "full_refresh", "append"], tmp_path: Path+ ) -> None:+ delta_path = str(tmp_path / "table")+ helper = make_local_table_ref(delta_path)++ with patch.object(helper, "_open_delta_table", AsyncMock(side_effect=helper._open_delta_table)) as probe:+ # The loader reads the table before it hands the batch to the writer.+ assert await helper.get_delta_table() is None++ first = await DeltaWriter(helper).write(+ data=pa.table({"id": pa.array([1, 2], pa.int64())}),+ write_type=write_type,+ should_overwrite_table=True,+ primary_keys=["id"],+ )+ assert await helper.get_delta_table() is first+ assert first.version() == deltalake.DeltaTable(delta_path).version()++ await DeltaWriter(helper).write(+ data=pa.table({"id": pa.array([3], pa.int64())}),+ write_type=write_type,+ should_overwrite_table=False,+ primary_keys=["id"],+ )+ current = await helper.get_delta_table()++ assert probe.await_count == 1+ assert current is not None+ assert current.version() == deltalake.DeltaTable(delta_path).version()+ assert set(current.to_pyarrow_table().column("id").to_pylist()) == {1, 2, 3}++ @pytest.mark.parametrize(+ "should_overwrite_table, expected_ids",+ [(False, {1, 2, 9}), (True, {1, 2})],+ ids=["continuation_appends_to_it", "overwrite_replaces_it"],+ )+ @pytest.mark.asyncio+ async def test_table_created_by_another_writer_after_the_probe(+ self, should_overwrite_table: bool, expected_ids: set[int], tmp_path: Path+ ) -> None:+ delta_path = str(tmp_path / "table")+ helper = make_local_table_ref(delta_path)+ assert await helper.get_delta_table() is None+ deltalake.write_deltalake(delta_path, pa.table({"id": pa.array([9], pa.int64())}))++ result = await DeltaWriter(helper).write(+ data=pa.table({"id": pa.array([1, 2], pa.int64())}),+ write_type="incremental",+ should_overwrite_table=should_overwrite_table,+ primary_keys=["id"],+ )++ assert set(result.to_pyarrow_table().column("id").to_pylist()) == expected_ids++class TestUnpartitionedTableWithPartitionKeyColumn:"""A Delta table can carry `_ph_partition_key` in its schema while itspartition_columns metadata is empty `[]` — e.g. the SchemaMismatchError fallback indiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/writer.pyindex c52c917b29d0..9b20e5a228d7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/writer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/writer.py@@ -382,7 +382,11 @@ class DeltaWriter:# nullability that matches its data (see relax_batch_nullability).data = relax_batch_nullability(data)- delta_table = await self._table.get_delta_table()+ # A write that overwrites the table gives the same result with or without a table there, so+ # a probe that the caller made through the same ref a moment ago is enough. Any other write+ # looks again: a table that another writer created since then must be appended to, not+ # replaced.+ delta_table = await self._table.get_delta_table(allow_known_missing=should_overwrite_table)if delta_table:delta_table = await evolve_delta_schema(delta_table, data.schema)@@ -581,6 +585,7 @@ class DeltaWriter:mode="ignore",configuration=DELTA_TABLE_PROPERTIES,)+ self._table.adopt_created_table(delta_table)if mode == "append":# Each batch of a full_refresh (or first incremental sync) infers its own decimal@@ -638,6 +643,7 @@ class DeltaWriter:mode="ignore",configuration=DELTA_TABLE_PROPERTIES,)+ self._table.adopt_created_table(delta_table)else:# An append re-casts each source column to its stored type, same as a merge. A decimal# column that outgrew decimal128 arrives here as text (decimal256 renders to string),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.pyindex d05974f96a94..568b924e8b1a 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@@ -1078,6 +1078,8 @@ def _process_message_reported(job=job,logger=logger,is_first_sync=export_signal.is_first_ever_sync,+ # Batch 0 of a first sync writes the table, so only that batch expects to find none.+ expect_missing=export_signal.is_first_ever_sync and export_signal.batch_index == 0,)if not warehouse_is_a_destination(export_signal):diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.pyindex 851cb8a352f0..ebc5f3e5f71c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py@@ -199,7 +199,9 @@ class PipelineV3(Generic[ResumableData]):or source_response.cdc_write_mode is not None)- self._delta_table_ref = DeltaTableRef(self._resource_name, self._job, self._logger)+ self._delta_table_ref = DeltaTableRef(+ self._resource_name, self._job, self._logger, expect_missing=models.table is None+ )attempt = current_import_attempt()self._attempt = attemptdiff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.pyindex db77645f8391..c965028df362 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py@@ -540,7 +540,9 @@ def compute_table_statistics_sync(team_id: int, schema_id: uuid.UUID) -> dict[stjob.schema = schemaresource_name = schema.resolved_s3_folder_name or schema.name- delta_table_ref = DeltaTableRef(resource_name=resource_name, job=job, logger=log)+ delta_table_ref = DeltaTableRef(+ resource_name=resource_name, job=job, logger=log, expect_missing=schema.table_id is None+ )delta_table = async_to_sync(delta_table_ref.get_delta_table)()if delta_table is None:emit_completed("skipped", reason="no_delta_table")diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.pyindex f4ec2a36c65a..fb5dcd043592 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py@@ -357,7 +357,9 @@ def _maybe_repartition_table(inputs: RepartitionActivityInputs, logger: Filterin# `public.users`, folder `users`), and the pipeline writes there too. Deriving the folder from# `name` alone probes a path that was never written and the repartition skips as `no_delta_table`.resource_name = schema.resolved_s3_folder_name or schema.name- table_ref = DeltaTableRef(resource_name=resource_name, job=job, logger=logger)+ table_ref = DeltaTableRef(+ resource_name=resource_name, job=job, logger=logger, expect_missing=schema.table_id is None+ )if pending is None and swap is None:# Nothing was queued by a prior run's post-load detection. Measure now and self-flag if it'sdiff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.pyindex 27109d03cfd2..ceb36530f093 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py@@ -672,7 +672,7 @@ class TestComputeTableStatisticsSync:add_actions = pa.table({"num_records": [1], "null_count.amount": [0], "min.amount": [1], "max.amount": [1]})captured: dict = {}- def _capture_helper(*, resource_name, job, logger):+ def _capture_helper(*, resource_name, job, logger, **_kwargs):captured["job"] = jobreturn self._mock_delta(add_actions)