Skip to content

Commit e61ae61

Browse files
committed
fix: Reject DeltaFormat saved-dataset storage in the Dask offline store
DaskRetrievalJob.persist wrote plain Parquet files even when the saved dataset storage declared DeltaFormat, so creation succeeded while retrieval failed: the Dask Delta reader requires a transaction log. Reject DeltaFormat saved-dataset storage before writing anything, and raise a recovery-guidance error when a DeltaFormat source has no Delta transaction log, covering saved datasets that earlier Feast versions wrote as plain Parquet under a Delta declaration. Signed-off-by: Benson LUO <luopengllpp@hotmail.com>
1 parent 2c1dd25 commit e61ae61

3 files changed

Lines changed: 124 additions & 3 deletions

File tree

‎docs/reference/offline-stores/dask.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ data files removed by an overwrite or compaction are not included. Use an absolu
99
local Delta path when Feast needs to infer the source schema, because `FileSource`
1010
schema discovery does not resolve that path relative to the repository.
1111

12+
Saved datasets are written as Parquet. `DaskRetrievalJob.persist` rejects
13+
`SavedDatasetFileStorage(file_format=DeltaFormat())` instead of writing Parquet
14+
files under a Delta declaration, because such a directory has no Delta transaction
15+
log and cannot be read back as a Delta table. Saved datasets that an earlier Feast
16+
version wrote as plain Parquet under a DeltaFormat declaration are also not valid
17+
Delta tables: re-create them with `ParquetFormat` storage, or register the
18+
directory as a ParquetFormat `FileSource` to keep reading the existing Parquet
19+
files.
20+
1221
When an entity dataframe is supplied to `get_historical_features`, entity rows and
1322
their additional columns (such as training labels) are retained even if all matching
1423
feature records are outside the feature view's TTL window or after the entity

‎sdk/python/feast/infra/offline_stores/dask.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ def persist(
129129
):
130130
assert isinstance(storage, SavedDatasetFileStorage)
131131

132+
if isinstance(storage.file_options.file_format, DeltaFormat):
133+
raise NotImplementedError(
134+
f"The Dask offline store cannot persist a saved dataset to "
135+
f"'{storage.file_options.uri}' with file format DeltaFormat; "
136+
"only Parquet saved datasets are supported. Writing Parquet "
137+
"files under a DeltaFormat declaration would create a "
138+
"directory without a Delta transaction log, which the Dask "
139+
"reader rejects on retrieval. Persist with ParquetFormat "
140+
"storage instead. To serve a saved dataset from a Delta "
141+
"table, write the retrieval result with a Delta writer and "
142+
"register a FileSource with file_format=DeltaFormat pointing "
143+
"at it."
144+
)
145+
132146
# Check if the specified location already exists.
133147
if not allow_overwrite and os.path.exists(storage.file_options.uri):
134148
raise SavedDatasetLocationAlreadyExists(location=storage.file_options.uri)
@@ -1197,7 +1211,26 @@ def _read_datasource(
11971211
if _is_delta_source(data_source):
11981212
# Delta supplies the snapshot schema and partition expressions and
11991213
# rejects reader features it cannot honor. Read data only in Dask tasks.
1200-
dataset = _read_delta_table(data_source, path).to_pyarrow_dataset()
1214+
from deltalake.exceptions import TableNotFoundError
1215+
1216+
try:
1217+
delta_table = _read_delta_table(data_source, path)
1218+
except TableNotFoundError as exc:
1219+
# Covers both genuinely missing tables and the legacy
1220+
# saved-dataset directories written as plain Parquet while
1221+
# declaring DeltaFormat, which older Feast versions accepted.
1222+
raise TableNotFoundError(
1223+
f"Delta source '{path}' has no Delta transaction log "
1224+
"(_delta_log), so it cannot be read as a Delta table: "
1225+
"directories that only contain Parquet files are not Delta "
1226+
"tables. If this is a saved dataset written by an earlier "
1227+
"Feast version that ignored the DeltaFormat declaration and "
1228+
"wrote plain Parquet, re-create the saved dataset with "
1229+
"ParquetFormat storage, or register the directory as a "
1230+
"ParquetFormat FileSource to read the existing Parquet files "
1231+
"directly."
1232+
) from exc
1233+
dataset = delta_table.to_pyarrow_dataset()
12011234
fragments = list(dataset.get_fragments())
12021235
meta = dataset.schema.empty_table().to_pandas(types_mapper=_delta_pandas_dtype)
12031236
if not fragments:

‎sdk/python/tests/unit/infra/offline_stores/test_dask_delta_source.py‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pathlib import Path
1818
from unittest.mock import MagicMock
1919

20+
import dask.dataframe as dd
2021
import pandas as pd
2122
import pyarrow as pa
2223
import pyarrow.parquet as pq
@@ -26,8 +27,12 @@
2627
from feast.entity import Entity
2728
from feast.feature_view import FeatureView, Field
2829
from feast.infra.offline_stores import dask as dask_mod
29-
from feast.infra.offline_stores.dask import DaskOfflineStore, DaskOfflineStoreConfig
30-
from feast.infra.offline_stores.file_source import FileSource
30+
from feast.infra.offline_stores.dask import (
31+
DaskOfflineStore,
32+
DaskOfflineStoreConfig,
33+
DaskRetrievalJob,
34+
)
35+
from feast.infra.offline_stores.file_source import FileSource, SavedDatasetFileStorage
3136
from feast.infra.offline_stores.offline_store import RetrievalJob
3237
from feast.repo_config import RepoConfig
3338
from feast.types import Float32, Int32, Int64, UnixTimestamp, ValueType
@@ -892,3 +897,77 @@ def test_offline_write_batch_delta_raises_not_implemented(tmp_path: Path) -> Non
892897
)
893898
assert DeltaTable(delta_path).version() == old_version
894899
assert set(_physical_part_files(delta_path)) == old_files
900+
901+
902+
# ------------------------------------------------------------------ #
903+
# Saved datasets: persist guard and create/retrieve roundtrip
904+
# ------------------------------------------------------------------ #
905+
906+
907+
def _retrieval_df() -> pd.DataFrame:
908+
return pd.DataFrame(
909+
{
910+
"driver_id": pd.array([1001, 1002], dtype="int64"),
911+
"conv_rate": pd.array([0.5, 0.6], dtype="float32"),
912+
"event_timestamp": pd.to_datetime(
913+
[datetime(2026, 1, 4, tzinfo=timezone.utc)] * 2
914+
),
915+
}
916+
)
917+
918+
919+
def _retrieval_job(repo_path: Path) -> DaskRetrievalJob:
920+
return DaskRetrievalJob(
921+
evaluation_function=lambda: dd.from_pandas(_retrieval_df(), npartitions=1),
922+
full_feature_names=False,
923+
repo_path=str(repo_path),
924+
)
925+
926+
927+
def test_persist_rejects_delta_saved_dataset_storage(tmp_path: Path) -> None:
928+
job = _retrieval_job(tmp_path)
929+
storage = SavedDatasetFileStorage(
930+
path=str(tmp_path / "saved_dataset"), file_format=DeltaFormat()
931+
)
932+
933+
with pytest.raises(NotImplementedError, match="DeltaFormat"):
934+
job.persist(storage)
935+
936+
# The mismatch is rejected before anything is written.
937+
assert not os.path.exists(str(tmp_path / "saved_dataset"))
938+
939+
940+
def test_saved_dataset_parquet_roundtrip(tmp_path: Path) -> None:
941+
job = _retrieval_job(tmp_path)
942+
storage = SavedDatasetFileStorage(path=str(tmp_path / "saved_dataset"))
943+
944+
job.persist(storage)
945+
946+
# Retrieval reads the persisted dataset back through the reader the
947+
# offline store uses for historical retrieval.
948+
persisted_source = storage.to_data_source()
949+
assert isinstance(persisted_source, FileSource)
950+
retrieved = dask_mod._read_datasource(persisted_source, tmp_path)
951+
retrieved = retrieved.compute().sort_values("driver_id").reset_index(drop=True)
952+
original = _retrieval_df().sort_values("driver_id").reset_index(drop=True)
953+
assert retrieved["driver_id"].tolist() == original["driver_id"].tolist()
954+
assert retrieved["conv_rate"].tolist() == original["conv_rate"].tolist()
955+
assert len(retrieved) == len(original)
956+
957+
958+
def test_delta_labelled_parquet_directory_read_error_gives_recovery_guidance(
959+
tmp_path: Path,
960+
) -> None:
961+
from deltalake.exceptions import TableNotFoundError
962+
963+
# A saved-dataset directory as written by DaskRetrievalJob.persist before
964+
# this change: plain Parquet files saved under a DeltaFormat declaration.
965+
parquet_dir = str(tmp_path / "legacy_saved_dataset")
966+
os.makedirs(parquet_dir)
967+
pq.write_table(
968+
pa.table({"driver_id": pa.array([1001], type=pa.int64())}),
969+
os.path.join(parquet_dir, "part-0.parquet"),
970+
)
971+
972+
with pytest.raises(TableNotFoundError, match="earlier Feast version"):
973+
dask_mod._read_datasource(_delta_file_source(parquet_dir), tmp_path)

0 commit comments

Comments
 (0)