Repository navigation
feat: Retrieve historical features from SQL Server without an entity dataframe - #7164
NopeCharon wants to merge 4 commits into
Conversation
…dataframe MsSqlServerOfflineStore.get_historical_features did not accept start_date or end_date, so calling FeatureStore.get_historical_features without an entity_df failed with "unexpected keyword argument 'start_date'" on SQL Server. When entity_df is None, build the entity dataframe from the data itself: the distinct join keys that each feature view source has between start_date and end_date, with every row stamped at end_date. Each entity then gets its latest feature values within the TTL, matching the BigQuery, Spark and Trino offline stores. start_date and end_date default through compute_non_entity_date_range like the other stores. The keys are collected by a new ibis helper, build_entity_df_for_date_range_ibis, in a single UNION query that runs in SQL Server. It applies the source field mapping and the projection's join key map the same way the point-in-time join does, fills the join keys a feature view does not have with typed NULLs, and casts keys that appear in several sources to one type. Feature views without entities join on the timestamp only, so when no feature view has entities the entity dataframe is a single row at end_date. The helper only relies on the data source reader, so other ibis-based offline stores can use it. The SQL Server data source reader took a single argument, while the ibis helpers call it with the data source and the repo path, so every get_historical_features call on SQL Server raised a TypeError. Accept the repo path in the reader and the writer, like the Oracle store does. Document entity-less retrieval for SQL Server in the offline store reference, the feature retrieval concepts page and the FAQ. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
There was a problem hiding this comment.
Devin Review found 2 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| join_key_map = { | ||
| column.name: feature_view.projection.join_key_map.get( | ||
| column.name, column.name | ||
| ) | ||
| for column in feature_view.entity_columns | ||
| } |
There was a problem hiding this comment.
🔴 Incorrect features with partial key aliases
With a partial join_key_map, entity-less retrieval can return one customer's features for another customer. The generated dataframe retains every key, but get_historical_features_ibis passes only explicit aliases into the join. Unmapped keys never constrain matching or row IDs.
Learn more
The new helper completes a partial projection map with identity mappings, but it does not carry that completed map into historical retrieval. The row-ID generator uses only projection values whenever the projection map is nonempty. read_fv likewise returns the partial map instead of completing it, and point_in_time_join matches and deduplicates without the omitted keys. Distinct composite entities can therefore receive the same feature values.
Example: A feature view has (driver_id, customer_id) keys and projects only driver_id to origin_id. Source rows (1, 10) and (1, 20) have different ratings within the requested window. The helper generates both entity rows, but the join matches only driver 1 and gives both customers the rating selected by deduplication.
Recommended fix: Complete projection maps with identity mappings consistently in row-ID generation and feature-table joins, not just entity discovery. Add an end-to-end entity-less retrieval test with a partial alias and two rows sharing the aliased key but differing on an unaliased key.
Was this helpful? React with 👍 or 👎 to provide feedback.
| join_key_types: Dict[str, dt.DataType] = {} | ||
| for key_table in key_tables: | ||
| for column, column_type in key_table.schema().items(): | ||
| join_key_types.setdefault(column, column_type) |
There was a problem hiding this comment.
🔴 Integer key overflow across feature sources
When an INT source precedes a BIGINT source, join_key_types forces BIGINT keys into INT. A key above 2,147,483,647 makes SQL Server raise arithmetic overflow, aborting retrieval.
Learn more
The union uses the first observed type for each key rather than a type that can represent every source's values. Each source is explicitly cast to that type before the union, so SQL Server cannot apply its normal union type widening. Retrieval therefore depends on feature-view ordering.
Example: The first feature view stores driver_id as SQL Server INT. The second stores it as BIGINT and contains driver 3,000,000,000 within the requested window. Casting that second key to INT raises arithmetic overflow; reversing the feature-view order avoids the failure.
Recommended fix: Compute a lossless common type across all occurrences of each join key before constructing casts and typed NULLs. For signed integer sources, choose at least the widest integer type. Add coverage with the INT source first and an out-of-range BIGINT value.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7164 +/- ##
==========================================
+ Coverage 52.77% 52.91% +0.13%
==========================================
Files 459 459
Lines 58241 58276 +35
Branches 8592 8601 +9
==========================================
+ Hits 30737 30834 +97
+ Misses 25406 25344 -62
Partials 2098 2098
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Casting every source to the type of the first feature view could overflow when a BIGINT key followed an INT one. Use the common type of all occurrences instead. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
patelchaitany
left a comment
There was a problem hiding this comment.
The PR looks good overall, and thanks for fixing the INT/BIGINT type widening issue.
| join_key_map = { | ||
| column.name: feature_view.projection.join_key_map.get( | ||
| column.name, column.name | ||
| ) | ||
| for column in feature_view.entity_columns | ||
| } |
There was a problem hiding this comment.
Could you also address the partial join_key_map issue in the shared Ibis retrieval code? This is a pre-existing issue, not introduced by this PR, but including the fix here would be a nice improvement since the new retrieval path uses that code.
Unmapped entity keys should remain part of both the join conditions and row IDs. A regression test with multiple entity keys and only one renamed key would help cover this.
There was a problem hiding this comment.
…ty-retrieval Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com> # Conflicts: # sdk/python/tests/unit/infra/offline_stores/test_ibis.py
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
franciscojavierarceo
left a comment
There was a problem hiding this comment.
we need database-executing integration coverage for the new SQL Server retrieval path.
|
|
||
| module = "feast.infra.offline_stores.contrib.mssql_offline_store.mssql" | ||
| with ( | ||
| patch(f"{module}.get_ibis_connection", return_value=con), |
There was a problem hiding this comment.
this fixture replaces both the SQL Server connection and its TTL SQL with DuckDB equivalents, so the added tests never execute the new SQL Server query path. existing non-entity universal tests exclude SQL Server. we need a universal integration case enabled for SQL Server that calls FeatureStore.get_historical_features(...).to_df() and checks entity membership, latest-value selection and TTL behavior, as the component testing rule requires.
What this PR does / why we need it:
SQL Server didn't support entity-less historical retrieval.
MsSqlServerOfflineStore.get_historical_featuresdidn't acceptstart_dateorend_date, so this failed:This PR adds a non-entity mode that works the same way as in the BigQuery, Spark and Trino offline stores. When
entity_dfisNone, the entity dataframe is built from the data:start_dateandend_date.end_date, so each entity gets its latest feature values within the TTL.Details:
ibis.py,build_entity_df_for_date_range_ibis. It runs oneUNIONquery in SQL Server and then hands the result to the existingget_historical_features_ibispath. The helper only uses the data source reader, so other ibis-based stores can reuse it later. This PR doesn't change DuckDB, which has its own open PR (feat: DuckDB historical retrieval without entity dataframe #6108).custmapped tocustomer_idis read ascustomer_id, andwith_join_key_map({"driver_id": "origin_id"})produces anorigin_idcolumn. Join keys left out of a partial join key map keep their own name.NULLin its rows. If several sources share a key with different integer types, the key is cast to one type so the union is valid. Feature views without entities don't add rows, because they join on the timestamp only. If no feature view has entities, the entity dataframe is a single row atend_date.start_dateandend_dateget their defaults fromcompute_non_entity_date_range, like in the other stores.filter_by_created_timestampandfull_feature_nameswork as they do in entity-df mode.This also fixes a bug that broke every SQL Server
get_historical_featurescall, including entity-df mode. The shared ibis helpers call the data source reader asreader(data_source, repo_path), but the SQL Server reader took one argument, so the call raisedTypeError: _read_data_source() takes 1 positional argument but 2 were given. The reader and the writer now acceptrepo_path, like the Oracle store's.Here is the T-SQL the helper generates for two feature views with different join keys (
driver_id BIGINT,customer_idmapped fromcust):Docs: the MsSQL offline store reference now describes the mode. MsSQL is added to the list of supported stores on the feature retrieval concepts page and in the FAQ.
Which issue(s) this PR fixes:
Fixes #5837
Checks
git commit -s)Testing Strategy
Unit tests:
tests/unit/infra/offline_stores/test_ibis.pycoversbuild_entity_df_for_date_range_ibis:NULLfilling across feature views, with field mappings;tests/unit/infra/offline_stores/contrib/mssql_offline_store/test_mssql_non_entity_mode.pyrunsMsSqlServerOfflineStore.get_historical_featuresend to end, with an in-memory DuckDB connection standing in for SQL Server. It covers:full_feature_names;start_datedefault;filter_by_created_timestamp;The new tests fail on
master: withunexpected keyword argument 'start_date', and the entity-df test with the readerTypeError. The existing ibis unit tests still pass.ruff check,ruff format --checkandmypyon the changed modules are clean.Manual check: I compiled the helper's query with the ibis
mssqldialect (output above) to confirm it produces valid T-SQL with typedNULLs and the same timestamp bounds aspull_latest_from_table_or_query_ibis. I didn't run it against a live SQL Server.Misc