Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sdk/python/feast/infra/offline_stores/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,21 @@ def point_in_time_join(
>= entity_table[event_timestamp_col]
)

# Select the columns used below from each side of the join, rather than
# dropping the "_y" copies the join makes of clashing entity columns by
# name: features, timestamps and created columns can end in "_y" too
# (e.g. "pos_y").
kept_columns = [timestamp_field]
if created_timestamp_field:
kept_columns.append(created_timestamp_field)
kept_columns.extend(feature_refs)
feature_table = feature_table.inner_join(
entity_table, predicates, lname="", rname="{name}_y"
).select(
entity_table["entity_row_id"],
*[feature_table[c] for c in dict.fromkeys(kept_columns)],
)
Comment on lines +530 to 533

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.

🟡 Missing required universal retrieval regression

The point_in_time_join change adds only unit coverage, omitting the required universal integration regression. The component testing rule requires a universal test whenever retrieval behavior changes.

Learn more

The new tests exercise the Ibis helper directly, while historical retrieval also performs feature-name rewriting and source-column preparation in get_historical_features_ibis. The component testing requirement explicitly requires a universal integration test for retrieval changes. The diff adds no integration tests.

Example: A universal retrieval test requests a feature named pos_y through FeatureStore.get_historical_features and verifies its latest eligible value, including when full feature names are enabled.

Recommended fix: Add a regression case to the universal offline-store integration suite using the existing store fixtures. Exercise suffix-bearing feature names through the public retrieval API rather than only calling the Ibis helper.

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.

Added in c50c099: test_historical_features_with_names_ending_in_y in the universal historical retrieval tests requests pos_x, pos_y and y through FeatureStore.get_historical_features, from a source whose timestamp and created columns are ts_y and created_y, with and without full feature names. Without the fix it fails on DuckDB (Column 'ts_y' is not found in table, or Column 'pos_y' is not found in table when the timestamp columns have plain names); with it, it passes on the file and DuckDB stores.


cols_to_drop_y = [c for c in feature_table.columns if c.endswith("_y")]
feature_table = feature_table.drop(*cols_to_drop_y)

feature_table = deduplicate(
table=feature_table,
group_by_cols=["entity_row_id"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from feast.types import Float32, Int32, String
from feast.utils import _utc_now
from tests.universal.feature_repos.repo_configuration import (
Environment,
construct_universal_feature_views,
table_name_from_data_source,
)
Expand Down Expand Up @@ -730,6 +731,109 @@ def test_historical_features_field_mapping(
)


@pytest.mark.integration
@pytest.mark.universal_offline_stores
@pytest.mark.parametrize("full_feature_names", [True, False], ids=lambda v: str(v))
def test_historical_features_with_names_ending_in_y(
environment: Environment, full_feature_names: bool
) -> None:
store = environment.feature_store

now = datetime.now().replace(microsecond=0, second=0, minute=0)
tomorrow = now + timedelta(days=1)
day_after_tomorrow = now + timedelta(days=2)

# Feature, timestamp and created column names ending in "_y", which the
# point-in-time join also uses for its own suffixes.
positions_df = pd.DataFrame(
data=[
{
"driver_id": 1001,
"pos_x": 1.5,
"pos_y": 7.5,
"y": 1,
"ts_y": now,
"created_y": now,
},
{
"driver_id": 1001,
"pos_x": 2.5,
"pos_y": 8.5,
"y": 2,
"ts_y": tomorrow,
"created_y": tomorrow,
},
{
"driver_id": 1002,
"pos_x": 3.5,
"pos_y": 9.5,
"y": 3,
"ts_y": now,
"created_y": now,
},
]
)
entity_df = pd.DataFrame(
data=[
{
"driver_id": 1001,
"event_timestamp": now + timedelta(hours=12),
"request_id": 1,
},
{
"driver_id": 1001,
"event_timestamp": day_after_tomorrow,
"request_id": 2,
},
{
"driver_id": 1002,
"event_timestamp": day_after_tomorrow,
"request_id": 3,
},
]
)

positions_source = environment.data_source_creator.create_data_source(
df=positions_df,
destination_name=f"test_driver_positions_{int(time.time_ns())}_{random.randint(1000, 9999)}",
timestamp_field="ts_y",
created_timestamp_column="created_y",
)
driver = Entity(name="driver", join_keys=["driver_id"])
positions_fv = FeatureView(
name="driver_positions",
entities=[driver],
schema=[
Field(name="pos_x", dtype=Float32),
Field(name="pos_y", dtype=Float32),
Field(name="y", dtype=Int32),
],
source=positions_source,
)
store.apply([driver, positions_fv])

actual_df = store.get_historical_features(
entity_df=entity_df,
features=[
"driver_positions:pos_x",
"driver_positions:pos_y",
"driver_positions:y",
],
full_feature_names=full_feature_names,
).to_df()

prefix = "driver_positions__" if full_feature_names else ""
expected_df = pd.DataFrame(
data=[
{"request_id": 1, "pos_x": 1.5, "pos_y": 7.5, "y": 1},
{"request_id": 2, "pos_x": 2.5, "pos_y": 8.5, "y": 2},
{"request_id": 3, "pos_x": 3.5, "pos_y": 9.5, "y": 3},
]
).rename(columns={name: f"{prefix}{name}" for name in ["pos_x", "pos_y", "y"]})

validate_dataframes(expected_df, actual_df, sort_by=["request_id"])


@pytest.mark.integration
@pytest.mark.universal_offline_stores(only=["file"])
def test_historical_features_non_entity_retrieval(environment):
Expand Down
85 changes: 85 additions & 0 deletions sdk/python/tests/unit/infra/offline_stores/test_ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,91 @@ def test_point_in_time_join_keeps_entity_rows_apart():
assert rows == {"1": (1.0, 110.0), "11": (11.0, 10.0), "7": (7.0, None)}


def test_point_in_time_join_keeps_features_whose_name_ends_in_y():
"""A feature named like "pos_y" is returned, not dropped with the "_y"
copies of the entity columns that the join renames."""
entity_table = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 3)] * 2,
}
)
positions = pa.table(
{
"driver_id": [1, 1, 2],
"event_timestamp": [
pa_datetime(2024, 1, 1),
pa_datetime(2024, 1, 2),
pa_datetime(2024, 1, 1),
],
"created": [
pa_datetime(2024, 1, 1),
pa_datetime(2024, 1, 2),
pa_datetime(2024, 1, 1),
],
"pos_x": [1.0, 2.0, 3.0],
"pos_y": [10.0, 20.0, 30.0],
}
)

actual = point_in_time_join(
ibis.memtable(entity_table),
feature_tables=[
(
ibis.memtable(positions),
"event_timestamp",
"created",
{"driver_id": "driver_id"},
["pos_x", "pos_y"],
timedelta(days=10),
)
],
).to_pyarrow()

rows = {
row["driver_id"]: (row["pos_x"], row["pos_y"]) for row in actual.to_pylist()
}
assert rows == {1: (2.0, 20.0), 2: (3.0, 30.0)}


def test_point_in_time_join_allows_columns_named_like_the_y_copies():
"""Feature-table columns named like the "_y" copies the join makes of
clashing entity columns ("driver_id_y", "event_timestamp_y") do not clash
with them, whether they are requested or not."""
entity_table = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 3)] * 2,
}
)
features = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 1)] * 2,
"created": [pa_datetime(2024, 1, 1)] * 2,
"driver_id_y": [10.0, 20.0],
"event_timestamp_y": [pa_datetime(2023, 1, 1)] * 2,
}
)

actual = point_in_time_join(
ibis.memtable(entity_table),
feature_tables=[
(
ibis.memtable(features),
"event_timestamp",
"created",
{"driver_id": "driver_id"},
["driver_id_y"],
timedelta(days=10),
)
],
).to_pyarrow()

rows = {row["driver_id"]: row["driver_id_y"] for row in actual.to_pylist()}
assert rows == {1: 10.0, 2: 20.0}


@pytest.mark.parametrize(
"dtype",
["datetime64[ns, UTC]", "datetime64[us, UTC]", "datetime64[ns]", "datetime64[us]"],
Expand Down
Loading