Skip to content
Open
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
41 changes: 36 additions & 5 deletions sdk/python/feast/infra/offline_stores/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,49 @@ def point_in_time_join(
select_cols.extend(feature_refs)
feature_table = feature_table.select(select_cols)

# Track the feature columns we're adding
all_feature_cols.extend(feature_refs)

# Select each side's columns explicitly instead of relying on the join's
# name resolution: a feature name that clashes with an entity column is
# renamed to "{name}_yyyy" on the feature side, and the final select
# below would then fail to find it. A feature ref that clashes with an
# entity column wins (consistent with the inner join above, where the
# entity's clashing copy is not selected), so the entity column it
# shadows is not carried forward and the result cannot contain
# duplicate column names. Columns accumulated by earlier feature tables
# are re-selected from acc_table; refs new to this table come from
# feature_table.
shadowed = set(feature_refs)
entity_cols_out = [
c for c in entity_columns if c != "entity_row_id" and c not in shadowed
]
Comment on lines +561 to +564

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 columns after an earlier collision

When a feature replaces an entity column, point_in_time_join selects that feature twice on the next join with different names. Ibis rejects the duplicate, so historical retrieval returns no dataset.

Learn more

Historical retrieval processes feature views in order and builds one accumulated table. When a feature shadows an entity column, the accumulated table contains only the feature under that name, but entity_columns still records the original entity schema. On a later join with a different feature name, the projection selects the already-shadowed name as both an entity column and a carried feature. Ibis rejects duplicate names in a projection.

Example: Pass an entity dataframe with trips and request positions:trips followed by rates:conv_rate. The second join selects the feature trips twice instead of returning it alongside conv_rate.

Recommended fix: Exclude both current and previously added feature names from the entity projection. Add a regression test combining entity-column shadowing with a subsequent view that contributes a different name.

Suggested change
shadowed = set(feature_refs)
entity_cols_out = [
c for c in entity_columns if c != "entity_row_id" and c not in shadowed
]
shadowed = set(feature_refs)
entity_cols_out = [
c
for c in entity_columns
if c != "entity_row_id" and c not in shadowed and c not in all_feature_cols
]

Devin Review


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

current_new_cols = [
c for c in dict.fromkeys(feature_refs) if c not in all_feature_cols
]
# refs earlier feature tables contributed, except those the current
# table's refs shadow: already present in acc_table
carried_cols = [c for c in all_feature_cols if c not in shadowed]
Comment on lines +565 to +570

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.

🔴 Both same-name features disappear

When an on-demand dependency repeats another view’s bare feature name, point_in_time_join drops both copies. The final projection still requests that name, so historical retrieval fails.

Learn more

An on-demand feature view computes features from other inputs. Historical retrieval includes its source features in the provider request but checks for name collisions only among explicitly requested features. With bare names, a source feature can therefore collide with a feature from another view in the Ibis join. The repeated name is excluded from both projections, but the final projection still includes it.

Example: Request drivers:score and customer_rating:adjusted_score, where customer_rating reads customers:score. The explicit names pass validation, but the second join removes score and the final projection cannot find it.

Recommended fix: Resolve collisions using the full source reference before projecting feature names, or reject ambiguous dependency names with a clear collision error. Do not silently pick one view’s value when a transformation needs the other. Add a historical retrieval test with a colliding implicit dependency.

Devin Review


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

acc_table = acc_table.left_join(
feature_table,
predicates=[feature_table.entity_row_id == acc_table.entity_row_id],
lname="",
rname="{name}_yyyy",
).select(
*[acc_table[c] for c in entity_cols_out],
acc_table["entity_row_id"],
*[acc_table[c] for c in carried_cols],
*[feature_table[c] for c in current_new_cols],
Comment on lines +577 to +580

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.

🔴 Fetched values overwrite on-demand inputs

When a fetched feature shares a required request-data name, point_in_time_join replaces the supplied value. The on-demand transform then computes historical features from the fetched value instead.

Learn more

An on-demand feature view can declare a request input that the caller supplies in the entity dataframe. Historical retrieval verifies that this input exists before the join, but the join discards it if a fetched feature has the same output name. The Arrow retrieval job passes the joined table to the on-demand transform, which reads the fetched value under the request input’s name. For example, the existing conversion-rate transform reads val_to_add directly from its input table.

Example: Request that conversion-rate transform and a separate view’s bare val_to_add feature, with the colliding view joined last. If the entity dataframe supplies val_to_add=5 but the feature supplies 10, the transform adds 10 and returns a valid-looking incorrect value.

Recommended fix: Keep required request data separate from the final feature-name projection until on-demand transformations have run. If the transform input schema cannot distinguish the sources, reject the collision before retrieval instead of substituting a value.

Devin Review


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

)

# Select only the columns we want: entity columns (minus entity_row_id) + all feature columns
final_cols = [c for c in entity_columns if c != "entity_row_id"] + all_feature_cols
all_feature_cols.extend(current_new_cols)

# Select only the columns we want: entity columns (minus entity_row_id,
# minus any column a feature ref shadows) + all feature columns. The
# feature refs are already deduplicated per table; deduplicate them across
# tables too, so two feature views contributing the same bare feature name
# (full_feature_names=False) do not produce a duplicate column.
entity_cols_out = [
c for c in entity_columns if c != "entity_row_id" and c not in set(all_feature_cols)
]
final_cols = entity_cols_out + list(dict.fromkeys(all_feature_cols))
acc_table = acc_table.select(final_cols)

return acc_table
Expand Down
215 changes: 215 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 @@ -286,6 +286,221 @@ def test_point_in_time_join_keeps_features_whose_name_ends_in_y():
assert rows == {1: (2.0, 20.0), 2: (3.0, 30.0)}


def test_point_in_time_join_with_entity_column_clashing_with_a_feature_name():
"""An entity dataframe column that shares its name with a requested feature
does not crash the join with a duplicate column; the feature value wins and
shadows the entity column (issue #8853 family, DuckDB/ibis path)."""
entity_table = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 3)] * 2,
"trips": [5, 6],
}
)
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),
],
"trips": [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"},
["trips"],
timedelta(days=10),
)
],
).to_pyarrow()

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


def test_point_in_time_join_full_feature_names_no_collision_with_entity_columns():
"""With full feature names the generated refs are prefixed with the feature
view name, so an entity column carrying the bare feature name cannot clash
and both columns come back."""
entity_table = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 3)] * 2,
"trips": [5, 6],
}
)
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),
],
"trips": [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"},
["positions__trips"],
timedelta(days=10),
)
],
).to_pyarrow()

rows = {
row["driver_id"]: (row["trips"], row["positions__trips"])
for row in actual.to_pylist()
}
assert rows == {1: (5, 20.0), 2: (6, 30.0)}


def test_point_in_time_join_full_feature_names_no_collision_with_entity_columns():

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.

this repeats the function defined at line 335, so Python replaces that test before pytest collects it. CI fails with F811, and the earlier case asks for positions__trips from a table that only has trips. we need to remove the invalid duplicate, retain the case with the renamed source column, and commit the formatter changes reported by the same job.

"""With full feature names the generated refs are prefixed with the feature
view name, so an entity column carrying the bare feature name cannot clash
and both columns come back."""
entity_table = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [pa_datetime(2024, 1, 3)] * 2,
"trips": [5, 6],
}
)
# read_fv renames the feature columns to "<fv>__<feature>" when
# full_feature_names is set; simulate that here.
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),
],
"positions__trips": [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"},
["positions__trips"],
timedelta(days=10),
)
],
).to_pyarrow()

rows = {
row["driver_id"]: (row["trips"], row["positions__trips"])
for row in actual.to_pylist()
}
assert rows == {1: (5, 20.0), 2: (6, 30.0)}


def test_point_in_time_join_accumulates_features_from_multiple_tables():
"""Feature columns accumulated from earlier feature tables survive the
left joins of later ones."""
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),
],
"trips": [10.0, 20.0, 30.0],
}
)
rates = pa.table(
{
"driver_id": [1, 2],
"event_timestamp": [
pa_datetime(2024, 1, 1),
pa_datetime(2024, 1, 1),
],
"created": [
pa_datetime(2024, 1, 1),
pa_datetime(2024, 1, 1),
],
"conv_rate": [0.5, 0.75],
}
)

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

rows = {
row["driver_id"]: (row["trips"], row["conv_rate"])
for row in actual.to_pylist()
}
assert rows == {1: (20.0, 0.5), 2: (30.0, 0.75)}


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
Expand Down
Loading