Repository navigation
feat: Retrieve historical features from Couchbase Columnar without an entity dataframe #7188
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 |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| from feast.on_demand_feature_view import OnDemandFeatureView | ||
| from feast.repo_config import FeastConfigBaseModel, RepoConfig | ||
| from feast.saved_dataset import SavedDatasetStorage | ||
| from feast.utils import compute_non_entity_date_range | ||
|
|
||
| from ... import offline_utils | ||
| from ...offline_utils import get_timestamp_filter_sql | ||
|
|
@@ -134,11 +135,12 @@ def get_historical_features( | |
| config: RepoConfig, | ||
| feature_views: List[FeatureView], | ||
| feature_refs: List[str], | ||
| entity_df: Union[pd.DataFrame, str], | ||
| entity_df: Optional[Union[pd.DataFrame, str]], | ||
| registry: BaseRegistry, | ||
| project: str, | ||
| full_feature_names: bool = False, | ||
| filter_by_created_timestamp: bool = False, | ||
| **kwargs: Any, | ||
| ) -> RetrievalJob: | ||
| """ | ||
| Retrieve historical features using point-in-time joins. | ||
|
|
@@ -152,6 +154,19 @@ def get_historical_features( | |
| for fv in feature_views: | ||
| assert isinstance(fv.batch_source, CouchbaseColumnarSource) | ||
|
|
||
| if entity_df is None: | ||
| return _get_historical_features_without_entity_df( | ||
| config=config, | ||
| feature_views=feature_views, | ||
| feature_refs=feature_refs, | ||
| registry=registry, | ||
| project=project, | ||
| full_feature_names=full_feature_names, | ||
| filter_by_created_timestamp=filter_by_created_timestamp, | ||
| start_date=kwargs.get("start_date"), | ||
| end_date=kwargs.get("end_date"), | ||
| ) | ||
|
|
||
| entity_schema = _get_entity_schema(entity_df, config) | ||
|
|
||
| entity_df_event_timestamp_col = ( | ||
|
|
@@ -468,6 +483,125 @@ def _get_entity_df_event_timestamp_range( | |
| return entity_df_event_timestamp_range | ||
|
|
||
|
|
||
| def _get_historical_features_without_entity_df( | ||
| config: RepoConfig, | ||
| feature_views: List[FeatureView], | ||
| feature_refs: List[str], | ||
| registry: BaseRegistry, | ||
| project: str, | ||
| full_feature_names: bool, | ||
| filter_by_created_timestamp: bool, | ||
| start_date: Optional[datetime], | ||
| end_date: Optional[datetime], | ||
| ) -> RetrievalJob: | ||
| """ | ||
| Retrieves historical features for a time range instead of an entity dataframe. | ||
|
|
||
| The left side of the point-in-time join is built from the entity keys observed | ||
| in the feature view sources between start_date and end_date, each joined as of | ||
| end_date, so every entity gets its latest feature values within the TTL. | ||
| """ | ||
| start_date, end_date = compute_non_entity_date_range( | ||
| feature_views, | ||
| start_date=start_date, | ||
| end_date=end_date, | ||
| ) | ||
|
|
||
| query_context = offline_utils.get_feature_view_query_context( | ||
| feature_refs, | ||
| feature_views, | ||
| registry, | ||
| project, | ||
| (start_date, end_date), | ||
| ) | ||
|
|
||
| entity_df_event_timestamp_col = offline_utils.DEFAULT_ENTITY_DF_EVENT_TIMESTAMP_COL | ||
| join_keys = offline_utils.gather_all_entities(query_context) | ||
| entity_df_columns = { | ||
| column: None for column in join_keys + [entity_df_event_timestamp_col] | ||
| }.keys() | ||
|
|
||
| query = build_point_in_time_query( | ||
| [asdict(context) for context in query_context], | ||
| left_table_query_string=_build_non_entity_left_table_query( | ||
| query_context=query_context, | ||
| join_keys=join_keys, | ||
| start_date=start_date, | ||
| end_date=end_date, | ||
| entity_df_event_timestamp_col=entity_df_event_timestamp_col, | ||
| ), | ||
| entity_df_event_timestamp_col=entity_df_event_timestamp_col, | ||
| entity_df_columns=entity_df_columns, | ||
| query_template=MULTIPLE_FEATURE_VIEW_POINT_IN_TIME_JOIN, | ||
| full_feature_names=full_feature_names, | ||
| filter_by_created_timestamp=filter_by_created_timestamp, | ||
| ) | ||
|
|
||
| return CouchbaseColumnarRetrievalJob( | ||
| query=query, | ||
| config=config, | ||
| full_feature_names=full_feature_names, | ||
| on_demand_feature_views=OnDemandFeatureView.get_requested_odfvs( | ||
| feature_refs, project, registry | ||
| ), | ||
| metadata=RetrievalMetadata( | ||
| features=feature_refs, | ||
| keys=join_keys, | ||
| min_event_timestamp=start_date, | ||
| max_event_timestamp=end_date, | ||
| ), | ||
| timestamp_field=entity_df_event_timestamp_col, | ||
| ) | ||
|
|
||
|
|
||
| def _build_non_entity_left_table_query( | ||
| query_context: List[offline_utils.FeatureViewQueryContext], | ||
| join_keys: List[str], | ||
| start_date: datetime, | ||
| end_date: datetime, | ||
| entity_df_event_timestamp_col: str, | ||
| ) -> str: | ||
| """ | ||
| Builds a subquery that stands in for the entity dataframe in non-entity mode. | ||
|
|
||
| It selects the distinct join keys of every feature view with entities whose | ||
| source has events between start_date and end_date, fills the join keys a | ||
| feature view does not have with null, and sets the event timestamp of every | ||
| row to end_date. Feature views without entities join on the timestamp alone, | ||
| so they do not contribute rows. When no feature view has entities, the | ||
| subquery is a single row holding end_date. | ||
| """ | ||
| start_timestamp = normalize_timestamp(start_date) | ||
| end_timestamp = normalize_timestamp(end_date) | ||
|
Comment on lines
+574
to
+575
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. 🟡 Truncated cutoff drops boundary events With fractional-second Learn moreThe default normalize_timestamp format omits fractional seconds and emits a compact UTC offset. The synthetic entity timestamp now uses that format for both source filtering and the point-in-time cutoff. In contrast, df_to_columnar writes fractional seconds with a colon-separated UTC offset. SQL++ string comparisons do not normalize these representations: a fractional timestamp sorts after the same-second cutoff because Example: With Recommended fix: Preserve microseconds in the synthetic timestamp and normalize source timestamps and bounds to comparable temporal values or a consistent canonical representation. Cover fractional cutoffs and exact inclusive boundaries using timestamps in the format written by Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| event_timestamp_col = _escape_column(entity_df_event_timestamp_col) | ||
|
|
||
| entity_selects = [] | ||
| for context in query_context: | ||
| if not context.entities: | ||
| continue | ||
| selections = dict(zip(context.entities, context.entity_selections)) | ||
| columns = ", ".join( | ||
| selections.get(join_key, f"null AS {join_key}") for join_key in join_keys | ||
| ) | ||
| entity_selects.append( | ||
| f"SELECT {columns} " | ||
| f"FROM {context.table_subquery} AS sub " | ||
| f"WHERE sub.{_escape_column(context.timestamp_field)} " | ||
| f"BETWEEN '{start_timestamp}' AND '{end_timestamp}'" | ||
| ) | ||
|
|
||
| if not entity_selects: | ||
| return f"(SELECT '{end_timestamp}' AS {event_timestamp_col})" | ||
|
|
||
| entity_union = "\n UNION ALL\n ".join(entity_selects) | ||
| return f"""( | ||
| SELECT DISTINCT entity_keys.*, '{end_timestamp}' AS {event_timestamp_col} | ||
| FROM ( | ||
| {entity_union} | ||
| ) AS entity_keys | ||
| )""" | ||
|
|
||
|
|
||
| def _escape_column(column: str) -> str: | ||
| """Wrap column names in backticks to handle reserved words.""" | ||
| return f"`{column}`" | ||
|
|
||
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.
🟡 Missing required universal retrieval coverage
The new
entity_df is Nonepath has only mocked unit coverage. The component rules require a universal integration case for retrieval changes. Existing entity-less integration cases exclude Couchbase, leaving generated SQL and returned values untested against this backend.Learn more
The component checklist requires a universal integration test for retrieval changes. The existing basic non-entity integration test runs only for Ray, while historical non-entity retrieval coverage restricts its corresponding case to the file store. The added unit tests inspect generated SQL or supply mocked query results, so they cannot validate SQL++ execution semantics.
Example: A generated cutoff can pass every SQL substring assertion while excluding the latest eligible event when Couchbase executes the query.
Recommended fix: Add a universal integration case enabled for Couchbase that retrieves without an entity dataframe and asserts actual entity keys, feature values, and timestamps. Include inclusive date boundaries and field mappings, and run the required local integration suite.
Was this helpful? React with 👍 or 👎 to provide feedback.