Repository navigation
fix: resolve entity-column and feature-name collisions in the ibis point-in-time join #7207
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
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 |
|---|---|---|
|
|
@@ -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 | ||
| ] | ||
| 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
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. 🔴 Both same-name features disappear When an on-demand dependency repeats another view’s bare feature name, Learn moreAn 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 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. 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
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. 🔴 Fetched values overwrite on-demand inputs When a fetched feature shares a required request-data name, Learn moreAn 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 Example: Request that conversion-rate transform and a separate view’s bare 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. 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(): | ||
|
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. 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 |
||
| """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 | ||
|
|
||
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.
🔴 Duplicate columns after an earlier collision
When a feature replaces an entity column,
point_in_time_joinselects 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_columnsstill 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
tripsand requestpositions:tripsfollowed byrates:conv_rate. The second join selects the featuretripstwice instead of returning it alongsideconv_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.
Was this helpful? React with 👍 or 👎 to provide feedback.