Repository navigation
fix: Restore feature table timestamp bounds in Snowflake point-in-time join - #7230
daniel-kristjansson wants to merge 3 commits into
Conversation
…e join Before feast-dev#4850 the Snowflake point-in-time template filtered each feature table on its timestamp column, using the entity dataframe's timestamp range: an upper bound at max_event_timestamp and, when the feature view has a TTL, a lower bound at min_event_timestamp. The ASOF JOIN template introduced in feast-dev#4850 dropped both predicates, so the feature table is scanned in full on every get_historical_features call and Snowflake cannot prune micro-partitions on the timestamp column. Restore both bounds in the template's subquery CTE, reusing the existing query context values. Each bound keeps a superset of the rows the ASOF JOIN and the TTL filter retain, so results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Daniel Kristjansson <danielk@cuymedia.net>
There was a problem hiding this comment.
Devin Review found 3 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
Addresses the Devin review comment "Nanosecond matches lost to truncation": feast-dev#7230 (comment) For a pandas entity dataframe, _get_entity_df_event_timestamp_range calls to_pydatetime(), which drops sub-microsecond digits, while the upload to Snowflake keeps them. The upper bound on the feature table could therefore be earlier than the latest entity timestamp and drop eligible feature rows in its final microsecond. Move the upper bound used for the feature table filter up by one millisecond. The retrieval job's metadata keeps the exact range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Daniel Kristjansson <danielk@cuymedia.net>
| entity_df_event_timestamp_range, | ||
| ( | ||
| entity_df_event_timestamp_range[0], | ||
| entity_df_event_timestamp_range[1] + timedelta(milliseconds=1), |
There was a problem hiding this comment.
When we do "entity_df_event_timestamp.max().to_pydatetime()" it drops the nanoseconds, so anything happening in the entity_df_event_timestamp_range[1] microsecond could would get filtered out before hitting our point-in-time query which is executed at full precision. Adding one microsecond would be enough padding but I figured there was no harm in adding a millisecond as the point-in-time query will filter any strays out.
franciscojavierarceo
left a comment
There was a problem hiding this comment.
the upper-bound precision padding addresses the nanosecond finding, but the other two pruning concerns still affect this Snowflake change. the range is measured before the retrieval job is returned, while _upload_entity_df reruns SQL when the job materializes, so a newer eligible row can be pruned using the old maximum. the DST lower bound also subtracts TTL before UTC conversion: with coerce_tz_aware=False, noon in New York on March 9 with a 24-hour TTL prunes a valid March 8 16:30 UTC feature. sharing that helper with other stores does not make either new predicate safe here. we need bounds from the uploaded entity snapshot and UTC elapsed-time arithmetic, with regressions for changing SQL input, spring-forward, and sub-microsecond timestamps before merging.
The feature-table pruning predicates in the point-in-time join could drop rows the ASOF join and per-row TTL would keep: - A SQL entity_df is executed again by _upload_entity_df when the job materializes. The bounds came from the earlier MIN/MAX, so newer entity rows lost their features. Measure MIN/MAX from the uploaded temp table instead. RetrievalMetadata keeps the range measured up front. - With coerce_tz_aware=False a ZoneInfo minimum made the TTL subtraction wall-clock arithmetic, an hour off across DST. Convert the minimum to UTC before the TTL is subtracted. The 1 ms upper-bound padding for sub-microsecond entity timestamps stays. The change is limited to the Snowflake store; the shared helpers in offline_utils are unchanged. Adds Snowflake integration regressions for the stale SQL snapshot, DST and sub-microsecond cases, and unit tests that check the rendered bounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Daniel Kristjansson <danielk@cuymedia.net>
|
I added the regression tests & added fixes for the pruning bound freshness & UTC issues. |
What this PR does / why we need it:
Partially restores feature-table pruning in the Snowflake point-in-time join. This addresses a performance regression introduced by #4850 ("Use ASOF JOIN in Snowflake offline store query", released in v0.43.0).
Before #4850, the Snowflake template filtered each feature table on its timestamp column, using the entity dataframe's timestamp range:
#4850 replaced the dedup +
LEFT JOINtemplate with the fasterASOF JOINtemplate, but dropped both predicates. The ASOF template has no filter on the feature table at all. On everyget_historical_featurescall, Snowflake scans every micro-partition of the feature table: clustering on the timestamp column cannot prune, and the TTL does not limit the scan.This PR restores both bounds inside the ASOF template's
__subqueryCTE, cast asTIMESTAMP '...'to matchget_timestamp_filter_sql:"<timestamp_field>" <= TIMESTAMP '<max entity timestamp + 1 ms>', always emitted."<timestamp_field>" >= TIMESTAMP '<min entity timestamp − TTL>', emitted only whenttl > 0. With unlimited TTL there is no lower bound.The predicates may only remove rows that the ASOF JOIN and the per-row TTL filter would discard anyway. To guarantee that:
entity_dfis re-executed by_upload_entity_dfwhen the job materializes, so the range is measured withMIN/MAXon the uploaded temp table, not reused fromget_historical_features()time. A DataFrameentity_dfis uploaded unchanged, so its in-memory range is used.RetrievalMetadata.min_event_timestamp/max_event_timestampstill report the range measured when the job is created.coerce_tz_aware=Falseand aZoneInfotimestamp, subtracting first is wall-clock arithmetic and is off by an hour across DST, while the SQL TTL counts elapsed seconds.The change is limited to the Snowflake store. The shared helpers in
offline_utils.pyare unchanged because BigQuery, Redshift and other stores also use them. Those stores can be fixed separately.Testing
tests/unit/infra/offline_stores/test_snowflake.py: renders the point-in-time SQL without a Snowflake account and checks the bounds for sub-microsecond entity timestamps, a spring-forward DST minimum, and a SQLentity_dfwhose result changes between job creation and upload.tests/integration/offline_store/test_snowflake_pruning.py: the same three cases end to end against Snowflake. Each one asserts that a feature row eligible for the join is still returned. These tests are skipped unlessSNOWFLAKE_CI_DEPLOYMENTis set, andmake test-python-integrationcurrently excludes Snowflake (-k "not snowflake"), so they run only manually for now. They pass against a real account, and the stale-SQL and DST tests fail without the fix.Benchmarks
We measured
get_historical_featureson production Snowflake feature tables clustered on the timestamp column. We compared two feature tables with different layouts, at entity dataframe sizes from ~100k to ~13M rows: