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
fixed merge conflicts
Signed-off-by: David Y Liu <davidyliuliu@gmail.com>
  • Loading branch information
mavysavydav committed Oct 8, 2021
commit 0b87a3bc2dc3587337caec701a8e4ac566bbe6c8
22 changes: 10 additions & 12 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def _populate_result_rows_from_feature_view(
):
original_table = (
table
if table.name == table.projection.name_to_use
if table.name == table.projection.name_to_use()
else self.get_feature_view(table.name)
)
entity_keys = _get_table_entity_keys(
Expand Down Expand Up @@ -1067,21 +1067,20 @@ def _get_feature_views_to_use(
)
}

fvs_to_use, od_fvs_to_use = [], []
if isinstance(features, FeatureService):
fvs_to_use, od_fvs_to_use = [], []
for fv_name, projection in [
(projection.name, projection)
for projection in features.feature_view_projections
]:
if fv_name in fvs:
fv_copy = copy.copy(fvs[fv_name])
fv_copy.set_projection(copy.copy(projection))
fvs_to_use.append(fv_copy)
fvs_to_use.append(
fvs[fv_name].with_projection(copy.copy(projection))
)
elif fv_name in od_fvs:
od_fv_copy = copy.copy(od_fvs[fv_name])
od_fv_copy.set_projection(copy.copy(projection))
od_fvs_to_use.append(od_fv_copy)
od_fvs_to_use.append(
od_fvs[fv_name].with_projection(copy.copy(projection))
)
else:
raise ValueError(
f"The provided feature service {features.name} contains a reference to a feature view"
Expand All @@ -1092,8 +1091,7 @@ def _get_feature_views_to_use(
else:
views_to_use = ([*fvs.values()], [*od_fvs.values()])

return fvs_to_use, od_fvs_to_use
return [*fvs.values()], [*od_fvs.values()]
return views_to_use

@log_exceptions_and_usage
def serve(self, port: int) -> None:
Expand Down Expand Up @@ -1161,11 +1159,11 @@ def _group_feature_refs(
""" Get list of feature views and corresponding feature names based on feature references"""

# view name to view proto
view_index = {view.projection.name_to_use: view for view in all_feature_views}
view_index = {view.projection.name_to_use(): view for view in all_feature_views}

# on demand view to on demand view proto
on_demand_view_index = {
view.projection.name_to_use: view for view in all_on_demand_feature_views
view.projection.name_to_use(): view for view in all_on_demand_feature_views
}

# view name to feature names
Expand Down
44 changes: 16 additions & 28 deletions sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ def with_name(self, name: str):

return cp

def with_join_key_map(self, join_key_map: Dict[str, str]):
"""
Produces a copy of this FeatureView with the passed join_key_map.
Comment thread
codyjlin marked this conversation as resolved.
Outdated

Args:
join_key_map: A map of existing entity join_key to a new join_key to use,
Comment thread
codyjlin marked this conversation as resolved.
Outdated
for example, if a feature data entity column name does not match the entity id name.

Returns:
A copy of this FeatureView with the name replaced with the 'name' input.
Comment thread
codyjlin marked this conversation as resolved.
Outdated
"""
cp = self.__copy__()
cp.projection.join_key_map = join_key_map

return cp

def with_projection(self, feature_view_projection: FeatureViewProjection):
"""
Sets the feature view projection by returning a copy of this feature view
Expand Down Expand Up @@ -272,34 +288,6 @@ def with_projection(self, feature_view_projection: FeatureViewProjection):

return cp

def with_join_key_map(self, join_key_map: Dict[str, str]):
"""
Produces a copy of this FeatureView with the passed join_key_map.

Args:
join_key_map: A map of existing entity join_key to a new join_key to use,
for example, if a feature data entity column name does not match the entity id name.

Returns:
A copy of this FeatureView with the name replaced with the 'name' input.
"""
fv = FeatureView(
name=self.name,
entities=self.entities,
ttl=self.ttl,
input=self.input,
batch_source=self.batch_source,
stream_source=self.stream_source,
features=self.features,
tags=self.tags,
online=self.online,
)

fv.set_projection(copy.copy(self.projection))
fv.projection.join_key_map = join_key_map

return fv

def to_proto(self) -> FeatureViewProto:
"""
Converts a feature view object to its protobuf representation.
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/feast/feature_view_projection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List
from typing import Dict, List, Optional

from attr import dataclass

Expand All @@ -21,7 +21,7 @@ def name_to_use(self):
def to_proto(self):
feature_reference_proto = FeatureViewProjectionProto(
feature_view_name=self.name,
feature_view_name_to_use=self.name_to_use,
feature_view_name_alias=self.name_alias,
join_key_map=self.join_key_map,
)
for feature in self.features:
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/feast/infra/offline_stores/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def evaluate_historical_retrieval():
# where there are very few characters available for use as separators
if full_feature_names:
formatted_feature_name = (
f"{feature_view.projection.name_to_use}__{feature}"
f"{feature_view.projection.name_to_use()}__{feature}"
)
else:
formatted_feature_name = feature
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/feast/infra/offline_stores/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def query_generator() -> Iterator[str]:
),
drop_columns=["entity_timestamp"]
+ [
f"{feature_view.projection.name_to_use}__entity_row_unique_id"
f"{feature_view.projection.name_to_use()}__entity_row_unique_id"
for feature_view in feature_views
],
)
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/feast/on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def __getitem__(self, item):

def with_name(self, name: str):
"""
Renames this feature view by setting an alias for the feature view name. This rename operation is only used as part of query operations and will not modify the underlying feature view.
Renames this on-demand feature view by returning a copy of this feature view with an alias
set for the feature view name. This rename operation is only used as part of query
operations and will not modify the underlying OnDemandFeatureView.

Args:
name: Name to assign to the OnDemandFeatureView copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_cli_apply_imported_featureview() -> None:

rc, output = runner.run_with_output(["apply"], cwd=repo_path)

print(f"DAVIDX: {output}")
assert rc == 0
assert b"Registered feature service driver_locations_service" in output

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.