Visitar URL original
Implement entity aliasing for feature retrieval by codyjlin · Pull Request #1868 · feast-dev/feast · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert changes using FVProjection
Signed-off-by: Cody Lin <codyl@twitter.com>
  • Loading branch information
Cody Lin
Cody Lin committed Oct 7, 2021
commit e5d8c767c56d96d5296c83366b829b8b3fecda4c
13 changes: 10 additions & 3 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ def get_historical_features(
all_feature_views, all_on_demand_feature_views = self._get_feature_views_to_use(
features
)
all_feature_views = _query_time_feature_views(
self.list_feature_views(), features
)
all_on_demand_feature_views = self._registry.list_on_demand_feature_views(
project=self.project
)
Expand Down Expand Up @@ -820,7 +823,8 @@ def get_online_features(
all_feature_views, all_on_demand_feature_views = self._get_feature_views_to_use(
features=features, allow_cache=True, hide_dummy_entity=False
)
all_feature_views = _use_time_feature_views(

all_feature_views = _query_time_feature_views(
self._list_feature_views(allow_cache=True, hide_dummy_entity=False),
features,
)
Expand Down Expand Up @@ -1102,9 +1106,12 @@ def _entity_row_to_field_values(
return result


def _use_time_feature_views(all_feature_views, features):
def _query_time_feature_views(
all_feature_views: List[FeatureView],
features: Optional[Union[List[str], FeatureService]],
) -> List[FeatureView]:
"""Look for use-time FeatureView.join_key_maps and update all_feature_views"""
if isinstance(features, FeatureService):
if features and isinstance(features, FeatureService):
feature_view_replacements = {
feature.name: feature
for feature in features.features
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/feast/infra/offline_stores/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _write_pyarrow_buffer_to_bq(
{{ featureview.created_timestamp_column ~ ' as created_timestamp,' if featureview.created_timestamp_column else '' }}
{{ featureview.entity_selections | join(', ')}}{% if featureview.entity_selections %},{% else %}{% endif %}
{% for feature in featureview.features %}
{{ feature }} AS {% if full_feature_names %}{{ featureview.name }}__{% if featureview.join_key_map %}{{ featureview.entities | join('_')}}__{% else %}{% endif %}{{feature}}{% else %}{% if featureview.join_key_map %}{{ featureview.entities | join('_')}}__{% else %}{% endif %}{{ feature }}{% endif %}{% if loop.last %}{% else %}, {% endif %}
{{ feature }} as {% if full_feature_names %}{{ featureview.name }}__{{feature}}{% else %}{{ feature }}{% endif %}{% if loop.last %}{% else %}, {% endif %}
{% endfor %}
FROM {{ featureview.table_subquery }}
WHERE {{ featureview.event_timestamp_column }} <= (SELECT MAX(entity_timestamp) FROM entity_dataframe)
Expand Down Expand Up @@ -603,7 +603,7 @@ def _write_pyarrow_buffer_to_bq(
SELECT
{{featureview.name}}__entity_row_unique_id
{% for feature in featureview.features %}
,{% if full_feature_names %}{{ featureview.name }}__{% if featureview.join_key_map %}{{ featureview.entities | join('_')}}__{% else %}{% endif %}{{feature}}{% else %}{% if featureview.join_key_map %}{{ featureview.entities | join('_')}}__{% else %}{% endif %}{{ feature }}{% endif %}
,{% if full_feature_names %}{{ featureview.name }}__{{feature}}{% else %}{{ feature }}{% endif %}
{% endfor %}
FROM {{ featureview.name }}__cleaned
) USING ({{featureview.name}}__entity_row_unique_id)
Expand Down
41 changes: 14 additions & 27 deletions sdk/python/feast/infra/offline_stores/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,39 +172,16 @@ def evaluate_historical_retrieval():
# Sort dataframe by the event timestamp column
df_to_join = df_to_join.sort_values(event_timestamp_column)

# Build a list of entity columns to join on (from the right table)
join_keys = []
for entity_name in feature_view.entities:
entity = registry.get_entity(entity_name, project)
join_key = (
feature_view.join_key_map[entity.join_key]
if feature_view.join_key_map
and entity.join_key in feature_view.join_key_map
else entity.join_key
)
join_keys.append(join_key)
right_entity_columns = join_keys
right_entity_key_columns = [
event_timestamp_column
] + right_entity_columns

# Build a list of all the features we should select from this source
feature_names = []
for feature in features:
# Modify the separator for feature refs in column names to double underscore. We are using
# double underscore as separator for consistency with other databases like BigQuery,
# where there are very few characters available for use as separators

fv_name_prefix = (
f"{feature_view.name}__" if full_feature_names else ""
)
join_keys_prefix = (
f"{'_'.join(join_keys)}__" if feature_view.join_key_map else ""
)
formatted_feature_name = (
f"{fv_name_prefix}{join_keys_prefix}{feature}"
)

if full_feature_names:
formatted_feature_name = f"{feature_view.name}__{feature}"
else:
formatted_feature_name = feature
# Add the feature name to the list of columns
feature_names.append(formatted_feature_name)

Expand All @@ -213,6 +190,16 @@ def evaluate_historical_retrieval():
columns={feature: formatted_feature_name}, inplace=True,
)

# Build a list of entity columns to join on (from the right table)
join_keys = []
for entity_name in feature_view.entities:
entity = registry.get_entity(entity_name, project)
join_keys.append(entity.join_key)
right_entity_columns = join_keys
right_entity_key_columns = [
event_timestamp_column
] + right_entity_columns

# Remove all duplicate entity keys (using created timestamp)
right_entity_key_sort_columns = right_entity_key_columns
if created_timestamp_column:
Expand Down
2 changes: 0 additions & 2 deletions sdk/python/feast/infra/offline_stores/offline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class FeatureViewQueryContext:
created_timestamp_column: Optional[str]
table_subquery: str
entity_selections: List[str]
join_key_map: Optional[Dict]


def get_feature_view_query_context(
Expand Down Expand Up @@ -151,7 +150,6 @@ def get_feature_view_query_context(
# TODO: Make created column optional and not hardcoded
table_subquery=feature_view.input.get_table_query_string(),
entity_selections=entity_selections,
join_key_map=feature_view.join_key_map,
)
query_context.append(context)
return query_context
Expand Down