From 9d696be303265278edeb9275ee6f5e7d5a3598b0 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Thapa Date: Fri, 13 Nov 2026 22:45:02 +0000 Subject: [PATCH] fix: Keep unmapped join keys in ibis point-in-time joins get_historical_features_ibis, used by the DuckDB offline store and the contrib Oracle and MSSQL stores, took a projection's join_key_map as the full list of join keys. When with_join_key_map renamed only some keys of a feature view with several entities, the other keys were left out of the join and of entity_row_id. Each entity row then got the latest value for the renamed key alone, taken from any value of the other keys. Build the map from the feature view's entity columns instead and keep the name of every key the projection does not rename, as the Dask and SQL offline stores and the online read path already do. Signed-off-by: Manoj Kumar Thapa --- sdk/python/feast/infra/offline_stores/ibis.py | 20 +++++--- .../unit/infra/offline_stores/test_ibis.py | 51 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/sdk/python/feast/infra/offline_stores/ibis.py b/sdk/python/feast/infra/offline_stores/ibis.py index 5f3bd686977..05da1cb316f 100644 --- a/sdk/python/feast/infra/offline_stores/ibis.py +++ b/sdk/python/feast/infra/offline_stores/ibis.py @@ -181,15 +181,24 @@ def _entity_row_id(entity_table: Table, columns: Iterable[str]): return r +def _join_key_map(feature_view: FeatureView) -> Dict[str, str]: + """Map each join key of the feature data to its column in the entity data. + + A projection's join_key_map may rename only some of the join keys; the + others keep their own name. + """ + return { + column.name: feature_view.projection.join_key_map.get(column.name, column.name) + for column in feature_view.entity_columns + } + + def _generate_row_id( entity_table: Table, feature_views: List[FeatureView], event_timestamp_col ) -> Table: all_entities = [event_timestamp_col] for fv in feature_views: - if fv.projection.join_key_map: - all_entities.extend(fv.projection.join_key_map.values()) - else: - all_entities.extend([e.name for e in fv.entity_columns]) + all_entities.extend(_join_key_map(fv).values()) entity_table = entity_table.mutate( entity_row_id=_entity_row_id(entity_table, set(all_entities)) @@ -285,8 +294,7 @@ def read_fv( fv_table, timestamp_field, created_timestamp_column, - feature_view.projection.join_key_map - or {e.name: e.name for e in feature_view.entity_columns}, + _join_key_map(feature_view), feature_refs, feature_view.ttl, ) diff --git a/sdk/python/tests/unit/infra/offline_stores/test_ibis.py b/sdk/python/tests/unit/infra/offline_stores/test_ibis.py index 20c10cd19e8..ddfa73fed41 100644 --- a/sdk/python/tests/unit/infra/offline_stores/test_ibis.py +++ b/sdk/python/tests/unit/infra/offline_stores/test_ibis.py @@ -8,11 +8,15 @@ import pyarrow.compute as pc import pytest +from feast import Entity, FeatureView, Field, FileSource from feast.infra.offline_stores.ibis import ( + get_historical_features_ibis, point_in_time_join, pull_all_from_table_or_query_ibis, pull_latest_from_table_or_query_ibis, ) +from feast.types import Int64 +from feast.value_type import ValueType def pa_datetime(year, month, day): @@ -278,3 +282,50 @@ def test_pull_filters_parquet_timestamps_of_any_precision(tmp_path, dtype, pull) ).to_arrow() assert sorted(table["driver_id"].to_pylist()) == [2, 3] + + +def test_get_historical_features_keeps_join_keys_left_out_of_join_key_map(): + """A join_key_map that renames only some join keys still joins on the others.""" + user = Entity(name="user", join_keys=["user_id"], value_type=ValueType.INT64) + merchant = Entity( + name="merchant", join_keys=["merchant_id"], value_type=ValueType.INT64 + ) + user_merchant = FeatureView( + name="user_merchant", + entities=[user, merchant], + schema=[ + Field(name="user_id", dtype=Int64), + Field(name="merchant_id", dtype=Int64), + Field(name="spend", dtype=Int64), + ], + source=FileSource(path="unused.parquet", timestamp_field="event_timestamp"), + ).with_join_key_map({"user_id": "sender_id"}) + features = pa.table( + { + "user_id": [1, 1], + "merchant_id": [100, 200], + "event_timestamp": [pa_datetime(2024, 1, 1), pa_datetime(2024, 1, 2)], + "spend": [10, 99], + } + ) + entity_df = pd.DataFrame( + { + "sender_id": [1, 1], + "merchant_id": [100, 200], + "event_timestamp": [datetime(2024, 1, 3, tzinfo=timezone.utc)] * 2, + } + ) + + actual = get_historical_features_ibis( + config=MagicMock(), + feature_views=[user_merchant], + feature_refs=["user_merchant:spend"], + entity_df=entity_df, + registry=MagicMock(), + project="test", + data_source_reader=lambda *_: ibis.memtable(features), + data_source_writer=MagicMock(), + ).to_df() + + spend = dict(zip(actual["merchant_id"], actual["spend"])) + assert spend == {100: 10, 200: 99}