Skip to content

feat: Retrieve historical features from SQL Server without an entity dataframe - #7164

Open
NopeCharon wants to merge 4 commits into
feast-dev:masterfrom
NopeCharon:feat/mssql-non-entity-retrieval
Open

NopeCharon wants to merge 4 commits into
feast-dev:masterfrom
NopeCharon:feat/mssql-non-entity-retrieval

Conversation

@NopeCharon

@NopeCharon NopeCharon commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

SQL Server didn't support entity-less historical retrieval. MsSqlServerOfflineStore.get_historical_features didn't accept start_date or end_date, so this failed:

store.get_historical_features(
    features=["driver_stats:conv_rate"],
    start_date=datetime(2025, 7, 1),
    end_date=datetime(2025, 7, 10),
)
# TypeError: MsSqlServerOfflineStore.get_historical_features() got an unexpected keyword argument 'start_date'

This PR adds a non-entity mode that works the same way as in the BigQuery, Spark and Trino offline stores. When entity_df is None, the entity dataframe is built from the data:

  • It takes the distinct join keys found in each feature view source between start_date and end_date.
  • Every row gets the timestamp end_date, so each entity gets its latest feature values within the TTL.

Details:

  • The keys are collected by a new helper in ibis.py, build_entity_df_for_date_range_ibis. It runs one UNION query in SQL Server and then hands the result to the existing get_historical_features_ibis path. 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).
  • Source field mappings and projection join key maps are applied the same way as in the point-in-time join. For example, a source column cust mapped to customer_id is read as customer_id, and with_join_key_map({"driver_id": "origin_id"}) produces an origin_id column. Join keys left out of a partial join key map keep their own name.
  • If a feature view doesn't have one of the join keys, that key is a typed NULL in 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 at end_date.
  • start_date and end_date get their defaults from compute_non_entity_date_range, like in the other stores. filter_by_created_timestamp and full_feature_names work as they do in entity-df mode.
  • Entity-df retrieval (pandas or SQL) is unchanged.

This also fixes a bug that broke every SQL Server get_historical_features call, including entity-df mode. The shared ibis helpers call the data source reader as reader(data_source, repo_path), but the SQL Server reader took one argument, so the call raised TypeError: _read_data_source() takes 1 positional argument but 2 were given. The reader and the writer now accept repo_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_id mapped from cust):

SELECT DISTINCT [t4].[driver_id], [t4].[customer_id]
FROM (
  SELECT * FROM (
    SELECT [t0].[driver_id], CAST(NULL AS VARCHAR(max)) AS [customer_id]
    FROM [driver_stats] AS [t0]
    WHERE [t0].[event_timestamp] >= DATETIME2FROMPARTS(2025, 7, 1, 0, 0, 0, 0, 6)
      AND [t0].[event_timestamp] <= DATETIME2FROMPARTS(2025, 7, 10, 0, 0, 0, 0, 6)
  ) AS [t2]
  UNION ALL
  SELECT * FROM (
    SELECT CAST(NULL AS BIGINT) AS [driver_id], [t1].[cust] AS [customer_id]
    FROM [customer_stats] AS [t1]
    WHERE [t1].[ts] >= DATETIME2FROMPARTS(2025, 7, 1, 0, 0, 0, 0, 6)
      AND [t1].[ts] <= DATETIME2FROMPARTS(2025, 7, 10, 0, 0, 0, 0, 6)
  ) AS [t3]
) AS [t4]

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

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

Unit tests:

  • tests/unit/infra/offline_stores/test_ibis.py covers build_entity_df_for_date_range_ibis:
    • the time range filter, deduplication and NULL filling across feature views, with field mappings;
    • full and partial projection join key maps;
    • keys of different types in different sources;
    • feature views without entities;
    • an empty range.
  • tests/unit/infra/offline_stores/contrib/mssql_offline_store/test_mssql_non_entity_mode.py runs MsSqlServerOfflineStore.get_historical_features end to end, with an in-memory DuckDB connection standing in for SQL Server. It covers:
    • latest values within the TTL;
    • multiple feature views with full_feature_names;
    • a feature view without entities;
    • the start_date default;
    • filter_by_created_timestamp;
    • an empty range;
    • a regression test for entity-df mode.

The new tests fail on master: with unexpected keyword argument 'start_date', and the entity-df test with the reader TypeError. The existing ibis unit tests still pass. ruff check, ruff format --check and mypy on the changed modules are clean.

Manual check: I compiled the helper's query with the ibis mssql dialect (output above) to confirm it produces valid T-SQL with typed NULLs and the same timestamp bounds as pull_latest_from_table_or_query_ibis. I didn't run it against a live SQL Server.

Misc


Devin Review

…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>
@NopeCharon
NopeCharon requested a review from a team as a code owner November 15, 2026 18:48

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 2 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +229 to +234
join_key_map = {
column.name: feature_view.projection.join_key_map.get(
column.name, column.name
)
for column in feature_view.entity_columns
}

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.

🔴 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.

Devin Review


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

Comment on lines +265 to +268
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)

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.

🔴 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.

Devin Review


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

@codecov-commenter

codecov-commenter commented Nov 15, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 89.18919% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.91%. Comparing base (6a1472f) to head (16b9842).

Files with missing lines Patch % Lines
sdk/python/feast/infra/offline_stores/ibis.py 90.32% 1 Missing and 2 partials ⚠️
...ffline_stores/contrib/mssql_offline_store/mssql.py 83.33% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@            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              
Flag Coverage Δ
go-feature-server 30.96% <ø> (ø)
python-unit 54.44% <89.18%> (+0.14%) ⬆️
Files with missing lines Coverage Δ
...ffline_stores/contrib/mssql_offline_store/mssql.py 69.33% <83.33%> (+69.33%) ⬆️
sdk/python/feast/infra/offline_stores/ibis.py 76.07% <90.32%> (+6.43%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a1472f...16b9842. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 patelchaitany left a comment

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.

The PR looks good overall, and thanks for fixing the INT/BIGINT type widening issue.

Comment on lines +229 to +234
join_key_map = {
column.name: feature_view.projection.join_key_map.get(
column.name, column.name
)
for column in feature_view.entity_columns
}

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.

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.

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.

This is already fixed on master (6a1472f, unmapped keys stay in the join and row IDs), and I merged it into the branch. The non-entity helper now reuses the same _join_key_map, and I added an end to end test with two keys where only driver_id is renamed: 16b9842

…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 franciscojavierarceo left a comment

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.

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),

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 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSSQL - historical retrieval without entity dataframe

4 participants