Repository navigation
fix: Join entity_df in local compute engine historical retrieval #7234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
cc0fa4b
32e27d0
5b01404
0e1c766
962ca9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| import logging | ||
| from typing import Union | ||
| from typing import List, Optional, Union | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from feast.aggregation import aggregation_specs_to_agg_ops | ||
| from feast.infra.common.materialization_job import MaterializationTask | ||
| from feast.infra.common.retrieval_task import HistoricalRetrievalTask | ||
| from feast.infra.compute_engines.backends.base import DataFrameBackend | ||
| from feast.infra.compute_engines.dag.node import DAGNode | ||
| from feast.infra.compute_engines.feature_builder import FeatureBuilder | ||
| from feast.infra.compute_engines.local.nodes import ( | ||
| LocalAggregationNode, | ||
| LocalDedupNode, | ||
| LocalEntityRowsNode, | ||
| LocalFilterNode, | ||
| LocalJoinNode, | ||
| LocalOutputNode, | ||
|
|
@@ -32,6 +36,45 @@ def __init__( | |
| super().__init__(registry, task.feature_view, task) | ||
| self.backend = backend | ||
|
|
||
| def _should_join_entity_df(self) -> bool: | ||
| # LocalJoinNode converts entity_df with pa.Table.from_pandas. | ||
| return isinstance(self.task, HistoricalRetrievalTask) and isinstance( | ||
| self.task.entity_df, pd.DataFrame | ||
| ) | ||
|
|
||
| def _build(self, view, input_nodes: Optional[List[DAGNode]]) -> DAGNode: | ||
| # Same steps as FeatureBuilder._build, but a source-backed view is | ||
| # joined with entity_df so the filter node can apply the point-in-time | ||
| # and TTL bounds per entity row. | ||
| if view.data_source: | ||
| last_node = self.build_source_node(view) | ||
|
|
||
| if self._should_transform(view): | ||
| last_node = self.build_transformation_node(view, [last_node]) | ||
|
|
||
| if self._should_join_entity_df(): | ||
| last_node = self.build_join_node(view, [last_node]) | ||
|
Comment on lines
+55
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Historical lookups fail for global features For views without entities, Learn moreFeatureView 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 Example: Request global ride counts at 12:00 with an entity DataFrame containing only 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. Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 32e27d0. A view without entities is cross joined with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, those requests were dropped. Fixed in 0e1c766 and 962ca9c. A new 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 Side effect: the aggregation path now also returns the other |
||
|
|
||
| elif input_nodes: | ||
| if self._should_transform(view): | ||
| last_node = self.build_transformation_node(view, input_nodes) | ||
| else: | ||
| last_node = self.build_join_node(view, input_nodes) | ||
| else: | ||
| raise ValueError(f"FeatureView {view.name} has no valid source or inputs") | ||
|
|
||
| last_node = self.build_filter_node(view, last_node) | ||
|
|
||
| if self._should_aggregate(view): | ||
| last_node = self.build_aggregation_node(view, last_node) | ||
| elif self._should_dedupe(view): | ||
| last_node = self.build_dedup_node(view, last_node) | ||
|
|
||
| if self._should_validate(view): | ||
| last_node = self.build_validation_node(view, last_node) | ||
|
|
||
| return last_node | ||
|
|
||
| def build_source_node(self, view): | ||
| start_time = self.task.start_time | ||
| end_time = self.task.end_time | ||
|
|
@@ -129,6 +172,19 @@ def build_validation_node(self, view, input_node): | |
| return node | ||
|
|
||
| def build_output_nodes(self, view, input_node): | ||
| node = LocalOutputNode("output", self.dag_root.view, inputs=[input_node]) | ||
| if self._should_join_entity_df(): | ||
| # The filter node dropped the entity rows that no feature row | ||
| # matched; return them with null features. | ||
| input_node = LocalEntityRowsNode( | ||
| "entity_rows", self.backend, inputs=[input_node] | ||
| ) | ||
| self.nodes.append(input_node) | ||
|
|
||
| node = LocalOutputNode( | ||
| "output", | ||
| self.dag_root.view, | ||
| inputs=[input_node], | ||
| write_to_stores=isinstance(self.task, MaterializationTask), | ||
| ) | ||
| self.nodes.append(node) | ||
| return node | ||
There was a problem hiding this comment.
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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 5b01404.
LocalOutputNodenow takes awrite_to_storesflag, andLocalFeatureBuildersets it only for aMaterializationTask, asFlinkFeatureBuilderdoes. Historical retrieval returns its rows and writes nothing.The write was there before this PR: on master a historical read of an
onlineview already makes oneonline_write_batchcall with the latest row per key, and a read of anofflineview raises inoffline_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(anonlineandofflineview read at an older timestamp, noonline_write_batchcall) andtest_materialization_still_writes_to_the_online_store. It is a separate commit in case it should go in on its own.