Skip to content

fix: Join entity_df in local compute engine historical retrieval - #7234

Open
Zhuoxi2000 wants to merge 5 commits into
feast-dev:masterfrom
Zhuoxi2000:fix-local-engine-historical-ignores-entity-df
Open

Zhuoxi2000 wants to merge 5 commits into
feast-dev:masterfrom
Zhuoxi2000:fix-local-engine-historical-ignores-entity-df

Conversation

@Zhuoxi2000

@Zhuoxi2000 Zhuoxi2000 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

LocalComputeEngine.get_historical_features ignored entity_df for source-backed feature views. LocalFeatureBuilder used the base FeatureBuilder._build, which only adds a join node when a view has upstream input_nodes. A source-backed view got source -> [transform] -> filter -> dedup, so the result was the latest row per join key across the whole source: unrequested entities came back, entity_df timestamps were ignored, and the point-in-time/TTL branch of LocalFilterNode never ran. LocalDedupNode also deduped on the join keys only, so an entity requested at two timestamps collapsed to one row.

Changes:

  • LocalFeatureBuilder._should_join_entity_df() and a _build override, mirroring TrinoFeatureBuilder / FlinkFeatureBuilder. After the source node (and the transformation, if any), a source-backed view is joined with entity_df when the task is a HistoricalRetrievalTask with a pandas entity_df. Only pandas is accepted because LocalJoinNode converts entity_df with pa.Table.from_pandas.
  • LocalJoinNode numbers the entity rows when it joins entity_df (__feast_entity_row_id, the ENTITY_ROW_ID the Flink engine already uses). Two entity rows can share their join keys and timestamp, so the timestamp alone does not tell them apart.
  • LocalDedupNode dedups on that row id when it is present, so there is one row per entity row. Without the id it falls back to the join keys plus __entity_event_timestamp.
  • LocalAggregationNode adds __entity_event_timestamp and the row id to its group-by keys when present. Without this, the join makes an aggregation over an entity requested at two timestamps return one row that sums both entity rows' windows (1.1 instead of 0.1 and 1.0 in the test), and two identical requests would be summed together.
  • LocalJoinNode no longer joins entity_df a second time when its first input already carries __entity_event_timestamp, and it joins such inputs on the join keys plus that column and the row id. Without this, a derived view (source=<another view>) ends up with __entity_event_timestamp_x/_y columns.
  • A feature view without entities has no join keys, so LocalJoinNode cross joins it with entity_df and the filter node picks the rows inside the point-in-time and TTL bounds.
  • LocalEntityRowsNode (new, last step before the output node for a historical task) left-joins the selected rows back onto the numbered entity rows by the row id. LocalFilterNode drops an entity row whose key has no feature row, or only rows after its timestamp or older than the TTL; that row now comes back with its entity_df columns and null features. The entity columns are taken from entity_df, and the result is sorted by the row id, so it is in entity_df order on either backend (its own small commit). LocalJoinNode and this node share one helper for numbering the rows and aliasing the timestamp.
  • LocalOutputNode drops the row id from the result.

Behavior change: historical retrieval through the local engine no longer writes to the stores. LocalOutputNode ended every plan, and wrote its rows to the online store when the view is online and to the offline store when it is offline. On master a historical read of an online view already made one online_write_batch call (with the latest row per key), and a read of an offline view raised in offline_write_batch. With the join, the rows are as of the entity timestamps, so reading an older value would have replaced the newer one being served. LocalOutputNode takes a write_to_stores flag (default True), and LocalFeatureBuilder sets it only for a MaterializationTask, as FlinkFeatureBuilder does. This is its own commit, in case you would rather take it separately.

The base FeatureBuilder is unchanged, so Spark and Ray are not affected by this PR.

Not covered here:

  • An entity row whose feature rows are all removed by the view's own filter expression also comes back with null features, the same as a row outside the point-in-time or TTL bounds.
  • The output keeps the __entity_event_timestamp column.
  • LocalEntityRowsNode needs the row id column to reach it. A transformation UDF that returns a frame without __feast_entity_row_id leaves the result as the filter produced it, so rows without features are not restored on that path.
  • A Polars entity_df still skips the join, because LocalJoinNode only converts pandas input. A pandas entity_df with the Polars backend is covered by the new tests.
  • Two entity rows with the same join keys and timestamp come back as two rows, as with the Flink engine. FeatureStore.get_historical_features with the Dask offline store returns one row for that input.
  • LocalAggregationNode groups by entity names, so an aggregation view whose entity name differs from its join key fails with a KeyError on master. That is unchanged; the new aggregation test uses an entity named after its join key.
  • A derived view with two source-backed parents fails on master with KeyError: 'event_timestamp' (the parents' timestamp columns collide in the join). That is unchanged.

Which issue(s) this PR fixes:

Fixes #7233

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

New tests in sdk/python/tests/unit/infra/compute_engines/test_local_compute_engine.py. Driver 1 has feature rows at t0 and t0+2h and is requested at t0+1h and t0+3h; driver 2 is not requested.

  • test_get_historical_features_is_point_in_time_per_entity_row: a source-backed view.
  • test_get_historical_features_for_derived_view: a view whose source is that view.
  • test_get_historical_features_aggregates_per_entity_row: a sum aggregation over the same source.

The first two expect two rows for driver 1 with conv_rate [0.1, 0.9]; the aggregation test expects sum_conv_rate [0.1, 1.0]. For the same inputs, FeatureStore.get_historical_features with the Dask offline store returns 0.1 and 0.9.

Added after the Devin Review comments, the first three on both the pandas and the Polars backend:

  • test_get_historical_features_keeps_entity_rows_with_the_same_key_and_time: driver 1 requested twice at t0+1h with labels a and b; both rows come back with conv_rate 0.1.
  • test_get_historical_features_aggregates_entity_rows_with_the_same_key_and_time: the same two requests through the sum view give [0.1, 0.1], not one row with 0.2.
  • test_get_historical_features_for_view_without_entities: a view with entities=[] requested at t0+1h and t0+3h gives [0.1, 0.9]. The Dask offline store returns the same for this input.
  • test_get_historical_features_does_not_write_to_the_stores: an online and offline view, read at t0+1h, returns 0.1 and makes no online_write_batch call.
  • test_materialization_still_writes_to_the_online_store: _materialize_one on an online view makes one online_write_batch call.

Added after the review, each on both backends and for an unmatched key (driver 3), a key whose only feature row is in the future (driver 2 at t0-1h) and a key whose only feature row is past the TTL (driver 2 at t0+2d). Each request is paired with a driver 1 request that does have a value, and the rows are told apart by a label:

  • test_get_historical_features_keeps_entity_rows_without_features: a source-backed view returns both rows in entity_df order, conv_rate 0.1 and null.
  • test_get_historical_features_for_derived_view_keeps_entity_rows: the same through a view whose source is that view.
  • test_get_historical_features_aggregation_keeps_entity_rows: the same through the sum view (sum_conv_rate 0.1 and null, labels kept).
  • test_get_historical_features_keeps_entity_rows_when_none_has_features: two requests, neither with a feature row; both come back with null conv_rate.
cd sdk/python
python -m pytest tests/unit/infra/compute_engines/test_local_compute_engine.py -q
  • With the two source files from master: 28 failed, 10 passed.
  • With the first three commits of this PR: 20 failed, 18 passed (the four tests just above, in all their parameters).
  • With all five commits: 38 passed.

The Polars parameters use pytest.importorskip("polars"). polars is not in sdk/python/requirements/py3.1*-ci-requirements.txt, so they run only where it is installed (locally, polars 2.2.0).

Related tests: tests/unit/infra/compute_engines with the Spark application, Trino and Snowflake modules left out (their optional dependencies aren't installed locally) gives 121 passed, 1 skipped, with polars 2.2.0 installed. tests/unit/test_type_map.py and tests/unit/test_feature_views.py fail 29 tests locally, all with No module named 'pyspark'.

ruff check and ruff format --check pass on the touched files, and mypy reports nothing in them locally apart from the missing pandas stubs.

Size: 3 files, +533/-18 (+161/-18 of source, +372 of tests).

Misc

Same gap that was flagged for the Trino engine in #6898 (comment). #5985 touches the timestamp-column guard in LocalDedupNode, #7004 edits the entity_df block of LocalJoinNode.execute a few lines from the guard added here, and #7028 adds incremental methods to LocalJoinNode, so whichever lands later may need a small rebase.


Devin Review

LocalFeatureBuilder used the base _build, which never joins entity_df
for a source-backed view. get_historical_features therefore returned
the latest row per join key across the whole source: unrequested
entities came back and the point-in-time/TTL filter never ran.

Override _build like the Trino and Flink builders and join entity_df
after the source (and transformation). Dedup and aggregate on the
entity timestamp as well as the entity keys, so an entity requested at
several timestamps keeps one row per entity row. LocalJoinNode no
longer joins entity_df a second time for a derived view whose inputs
already carry it.

Signed-off-by: Edson <zhuoxi2000@gmail.com>
@Zhuoxi2000
Zhuoxi2000 requested a review from a team as a code owner November 24, 2026 22:38

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +54 to +55
if self._should_join_entity_df():
last_node = self.build_join_node(view, [last_node])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Historical reads overwrite live features

When historical retrieval selects older rows for an online-enabled view, LocalOutputNode writes them to the online store. SQLite replaces newer serving values unconditionally. For offline-enabled Dask views, the added request timestamp makes the offline write reject the result.

Learn more

The local engine executes the historical plan when the caller reads the retrieval job’s result, as shown in LocalRetrievalJob. The builder still ends both historical and materialization plans with build_output_nodes, which calls stores through LocalOutputNode. Before the new join, source-backed retrieval deduplicated source values to the latest per entity; now it feeds historical values into an existing write path. SQLite’s upsert replaces the row without comparing timestamps. Dask’s offline writer requires exactly the source columns, which exclude the request timestamp.

Example: A driver has source values 0.1 at 10:00 and 0.9 at 12:00. SQLite is serving 0.9. Retrieving the driver at 11:00 returns and writes 0.1, so the next online lookup also serves 0.1. If the view also writes to Dask, the historical call raises after the online write.

Recommended fix: End historical plans with a read-only output node; reserve the store-writing node for materialization. Test an online-enabled view with a preloaded newer value and an offline-enabled view with a real source schema.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5b01404. LocalOutputNode now takes a write_to_stores flag, and LocalFeatureBuilder sets it only for a MaterializationTask, as FlinkFeatureBuilder does. Historical retrieval returns its rows and writes nothing.

The write was there before this PR: on master a historical read of an online view already makes one online_write_batch call with the latest row per key, and a read of an offline view raises in offline_write_batch. What this PR changed is which rows reached that write, so the overwrite described here was real.

Tests: test_get_historical_features_does_not_write_to_the_stores (an online and offline view read at an older timestamp, no online_write_batch call) and test_materialization_still_writes_to_the_online_store. It is a separate commit in case it should go in on its own.

Comment on lines +185 to +189
group_keys = list(self.group_keys)
# Aggregate per entity row after the entity_df join.
if ENTITY_TS_ALIAS in self.backend.columns(df):
group_keys.append(ENTITY_TS_ALIAS)
grouped_df = self.backend.groupby_agg(df, group_keys, self.agg_ops)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Duplicate requests inflate historical aggregates

When requests share a key and timestamp, LocalAggregationNode combines their copied feature rows and inflates sums and counts. LocalDedupNode also keeps only one of those requests, even when they carry different labels.

Learn more

The source join copies each matching feature row for every request with the same key, as in LocalJoinNode. A key and timestamp identify a lookup but do not uniquely identify a request row. The aggregation puts copies from different requests into one group, while LocalDedupNode chooses just one request from such a group. The derived join also uses the lookup pair in place of a request identifier.

Example: Two rides for driver 1 at 12:00 carry different training labels. One eligible source row has value 4. A sum yields one row with 8 instead of two rows with 4; non-aggregated retrieval keeps one ride.

Recommended fix: Assign a stable ID to each request before the join, as Flink’s entity preparation does. Use it to distinguish requests in deduplication, aggregation, and derived joins. Retain the request payload by ID and omit the internal ID from the final result.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 32e27d0. LocalJoinNode numbers the entity rows when it joins entity_df, with the ENTITY_ROW_ID column the Flink engine uses. LocalDedupNode dedups on that id, LocalAggregationNode groups by it, the join of already joined inputs uses it, and LocalOutputNode drops it from the result.

Two requests for driver 1 at the same timestamp with labels a and b now come back as two rows, and the sum view gives 0.1 for each instead of one row with 0.2. Both are tested on the pandas and the Polars backend.

One part is not done: an aggregation keeps only its group-by keys and the aggregated columns, so the label is not in an aggregation view's result. The non-aggregated path keeps it. I listed that under "Not covered" in the description.

Comment on lines +54 to +55
if self._should_join_entity_df():
last_node = self.build_join_node(view, [last_node])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Historical lookups fail for global features

For views without entities, LocalFeatureBuilder sends an empty key list to PandasBackend.join. The merge raises before the request timestamps can select any global feature values.

Learn more

FeatureView records a dummy entity for views without keys, and _get_column_names resolves their columns using the registry. The column resolver excludes the dummy key, so the new source join receives no keys. LocalJoinNode still requests a left equality join rather than handling that case explicitly, and pandas rejects on=[].

Example: Request global ride counts at 12:00 with an entity DataFrame containing only event_timestamp. A source row at 11:00 is eligible, but the merge raises an IndexError.

Recommended fix: Give keyless views a global point-in-time lookup instead of an empty-key left merge. Ensure LocalDedupNode selects one eligible value per request even when there are no entity keys.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 32e27d0. A view without entities is cross joined with entity_df, and the filter node keeps the feature rows inside the point-in-time and TTL bounds of each entity row. LocalDedupNode then keeps one row per entity row through the row id, so it no longer needs a join key.

test_get_historical_features_for_view_without_entities requests a view with entities=[] at two timestamps and gets 0.1 and 0.9, on the pandas and the Polars backend. FeatureStore.get_historical_features with the Dask offline store returns the same for that input.

@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 83.09859% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.17%. Comparing base (a291a0f) to head (962ca9c).

Files with missing lines Patch % Lines
...ast/infra/compute_engines/local/feature_builder.py 68.96% 4 Missing and 5 partials ⚠️
.../python/feast/infra/compute_engines/local/nodes.py 92.85% 1 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7234      +/-   ##
==========================================
+ Coverage   54.10%   54.17%   +0.06%     
==========================================
  Files         467      467              
  Lines       58940    59000      +60     
  Branches     8688     8701      +13     
==========================================
+ Hits        31890    31963      +73     
+ Misses      24892    24874      -18     
- Partials     2158     2163       +5     
Flag Coverage Δ
go-feature-server 30.96% <ø> (ø)
python-unit 55.77% <83.09%> (+0.07%) ⬆️
Files with missing lines Coverage Δ
.../python/feast/infra/compute_engines/local/nodes.py 88.31% <92.85%> (+0.93%) ⬆️
...ast/infra/compute_engines/local/feature_builder.py 68.26% <68.96%> (+12.42%) ⬆️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a291a0f...962ca9c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Two entity rows can share their join keys and timestamp. The dedup node
kept one of them and the aggregation node summed both into one row, and a
feature view without entities had no key to join on, so the join raised.

Number the entity rows when entity_df is joined, as the Flink engine does,
and use that id to dedup, to group and to join already joined inputs. A
view without entities is cross joined with entity_df. The id is dropped
from the output.

Signed-off-by: Edson <zhuoxi2000@gmail.com>
The local engine ended every plan with a node that writes its rows to the
online and offline stores of the feature view. For historical retrieval
those rows are now as of the entity timestamps, so reading an older value
would replace the newer one the online store serves.

Write only for materialization, as the Flink engine does.

Signed-off-by: Edson <zhuoxi2000@gmail.com>

@franciscojavierarceo franciscojavierarceo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to preserve every requested entity row when no feature survives the point-in-time filter.

last_node = self.build_transformation_node(view, [last_node])

if self._should_join_entity_df():
last_node = self.build_join_node(view, [last_node])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new source-backed historical path joins each request to candidate feature rows and then LocalFilterNode removes rows outside PIT/TTL bounds, but LocalRetrievalJob returns that filtered table directly. a request with no matching key, only future features, or only expired features therefore disappears instead of returning its entity row and null features; this can silently remove training examples. we need to left-join the selected results back to the original entity rows by ENTITY_ROW_ID before dropping that id, and cover unmatched, future-only, and expired-only requests on both backends.

@Zhuoxi2000 Zhuoxi2000 Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, those requests were dropped. Fixed in 0e1c766 and 962ca9c.

A new LocalEntityRowsNode runs just before the output node for a historical task and left-joins the selected rows back onto the numbered entity rows by ENTITY_ROW_ID, before LocalOutputNode drops the id. The entity columns are taken from entity_df, so a request with no surviving feature row comes back with its own columns and null features, and the result is sorted by the row id, so it is in entity_df order on both backends (962ca9c). LocalJoinNode and the new node share one helper for numbering the rows.

Tests, each on pandas and Polars and for an unmatched key, a future-only key and an expired-only key, always next to a request that does have a value: a source-backed view, a derived view, and the sum aggregation view. One more test covers a request set where no row has a feature. With the previous head's source files these are 20 failed / 18 passed; now 38 passed.

Side effect: the aggregation path now also returns the other entity_df columns (a label, for example), since they come from the join back. I updated the PR description to match.

The filter node drops an entity row when its key has no feature row, or
only rows after the entity timestamp or older than the TTL, and the
retrieval job returned the filtered table. Left-join the selected rows
back onto the entity rows by the entity row id before it is dropped, so
that every requested row is returned, with null features when nothing
was selected.

Signed-off-by: Edson <zhuoxi2000@gmail.com>
A backend's left join does not have to keep the order of the left
frame, so sort the joined rows by the entity row id.

Signed-off-by: Edson <zhuoxi2000@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalComputeEngine.get_historical_features ignores entity_df for source-backed feature views

3 participants