Skip to content

LocalComputeEngine.get_historical_features ignores entity_df for source-backed feature views #7233

In review

Description

@Zhuoxi2000

Expected Behavior

LocalComputeEngine.get_historical_features(registry, HistoricalRetrievalTask(...)) returns one point-in-time correct row per entity_df row. The compute engine docs describe get_historical_features() as "point-in-time correct training dataset retrieval" and list LocalHistoricalRetrievalJob as supported by the local engine. FeatureStore.get_historical_features (Dask offline store) returns that for the inputs below, and the Trino and Flink builders already join entity_df on this path.

Current Behavior

For a BatchFeatureView backed by a data source, the local engine returns the latest row per join key across the whole source:

  • entities that are not in entity_df come back;
  • the entity_df timestamps are ignored, so LocalFilterNode's point-in-time and TTL branch never runs (it only applies when __entity_event_timestamp is present);
  • an entity requested at two timestamps comes back once.

There are two causes:

  1. LocalFeatureBuilder inherits FeatureBuilder._build, which builds source -> [transform] -> filter -> dedup and only adds a join node when there are upstream input_nodes. entity_df is never joined for a source-backed view. TrinoFeatureBuilder and FlinkFeatureBuilder override _build with _should_join_entity_df() for this reason; the same gap was flagged as a blocker on the Trino PR: feat: Add Trino compute engine for batch retrieval and materialization #6898 (comment)
  2. LocalDedupNode dedups on the join keys only, and LocalAggregationNode groups by the entities only. Even with the join in place, an entity requested at two timestamps collapses to one row (and an aggregation would sum both entity rows together). The Trino dedup adds __entity_event_timestamp to its PARTITION BY, and Flink dedups on ENTITY_ROW_ID.

LocalSourceReadNode reads through create_offline_store_retrieval_job, which calls pull_latest_from_table_or_query / pull_all_from_table_or_query and does not use context.entity_df, so the offline store does not cover this either.

Scope: passthrough_provider does not route FeatureStore.get_historical_features to the batch engine yet (#6359), so this affects direct engine calls only.

Steps to reproduce

from datetime import datetime, timedelta, timezone
from unittest.mock import MagicMock
import pandas as pd

from feast import BatchFeatureView, Entity, Field, FileSource, RepoConfig, ValueType
from feast.infra.common.retrieval_task import HistoricalRetrievalTask
from feast.infra.compute_engines.local.compute import LocalComputeEngine
from feast.infra.offline_stores.dask import DaskOfflineStore, DaskOfflineStoreConfig
from feast.infra.online_stores.sqlite import SqliteOnlineStoreConfig
from feast.types import Float32, Int64

t0 = datetime(2026, 1, 1, tzinfo=timezone.utc)
pd.DataFrame(
    {
        "driver_id": [1, 1, 2],
        "conv_rate": [0.1, 0.9, 0.5],
        "event_timestamp": [t0, t0 + timedelta(hours=2), t0],
    }
).to_parquet("/tmp/driver_stats.parquet")

driver = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64)
view = BatchFeatureView(
    name="driver_stats",
    entities=[driver],
    mode="pandas",
    schema=[Field(name="driver_id", dtype=Int64), Field(name="conv_rate", dtype=Float32)],
    source=FileSource(path="/tmp/driver_stats.parquet", timestamp_field="event_timestamp"),
    ttl=timedelta(days=1),
    online=False,
    offline=False,
)
config = RepoConfig(
    project="repro",
    registry="/tmp/registry.db",
    provider="local",
    online_store=SqliteOnlineStoreConfig(path="/tmp/online.db"),
    offline_store=DaskOfflineStoreConfig(),
    entity_key_serialization_version=3,
)
engine = LocalComputeEngine(
    repo_config=config, offline_store=DaskOfflineStore(), online_store=MagicMock()
)

# driver 1 at t0+1h and t0+3h; driver 2 is not requested
entity_df = pd.DataFrame(
    {"driver_id": [1, 1], "event_timestamp": [t0 + timedelta(hours=1), t0 + timedelta(hours=3)]}
)
registry = MagicMock()
registry.get_entity.return_value = driver
task = HistoricalRetrievalTask(
    project="repro", entity_df=entity_df, feature_view=view,
    full_feature_name=False, registry=registry,
)
print(engine.get_historical_features(registry, task).to_df())

Expected: two rows for driver 1, with conv_rate 0.1 (as of t0+1h) and 0.9 (as of t0+3h). That is what FeatureStore.get_historical_features returns for the same source and entity_df.

Actual on master (a291a0f):

   conv_rate           event_timestamp  driver_id
0        0.9 2026-01-01 02:00:00+00:00          1
1        0.5 2026-01-01 00:00:00+00:00          2

A derived view (source=driver_stats, no transformation) goes through the join path and only returns one row for driver 1 (0.9 as of t0+3h).

Specifications

  • Version: master (a291a0f), feast 0.68.1.dev
  • Platform: macOS 26.5 arm64, Python 3.11.15, pandas 2.3.3, pyarrow 26.0.1
  • Subsystem: sdk/python/feast/infra/compute_engines/local

Possible Solution

Keep the base FeatureBuilder as is and fix the local engine only:

  1. Override _build in LocalFeatureBuilder as the Trino and Flink builders do: after the source node (and the transformation, if any), add build_join_node(view, [last_node]) when the task is a HistoricalRetrievalTask with a pandas entity_df.
  2. In LocalDedupNode and LocalAggregationNode, add __entity_event_timestamp to the dedup / group-by keys when that column is present.
  3. In LocalJoinNode, skip the trailing entity_df join when the first input already carries __entity_event_timestamp, and join such inputs on the join keys plus that column. Otherwise a derived view joins entity_df twice and ends up with __entity_event_timestamp_x/_y columns.

That is about 60 lines of source plus three unit tests in test_local_compute_engine.py (source-backed view, derived view, aggregation).

Out of scope:

  • Spark. SparkFeatureBuilder inherits the same base _build, and its read node also goes through create_offline_store_retrieval_job, so it may have the same gap, but I can't test Spark here. Is that path expected to join entity_df too, or is it covered somewhere I missed?
  • Entity rows with no feature row inside the TTL are dropped by LocalFilterNode rather than returned with nulls. That was already the case on the derived-view path.

Open PRs nearby: #5985 changes the timestamp-column guard in LocalDedupNode (same function, different change), #7004 changes how LocalJoinNode infers the entity_df timestamp column, and #7028 adds incremental methods to LocalJoinNode. None of them changes the join or dedup keys.

I'll open the PR for this myself, with the fix above and regression tests.

Activity

  1. Zhuoxi2000 commented on Nov 24, 2026

    @Zhuoxi2000
    ContributorAuthor

    I'd like to take this one myself and will open the PR. I have the fix and three regression tests ready locally (a source-backed view, a derived view on top of it, and an aggregation view). I'll open it shortly unless a maintainer would prefer a different approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions