Skip to content

Commit

Permalink
chore: Remove join_keys attribute (#3159)
Browse files Browse the repository at this point in the history
Remove `join_keys` attribute

Signed-off-by: Felix Wang <wangfelix98@gmail.com>

Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 authored Aug 31, 2022
1 parent 5ddb83b commit 857876b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
14 changes: 3 additions & 11 deletions sdk/python/feast/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class Entity:
Attributes:
name: The unique name of the entity.
value_type: The type of the entity, such as string or float.
join_keys: A list of properties that uniquely identifies different entities within the
collection. This currently only supports a list of size one, but is intended to
eventually support multiple join keys.
join_key: A property that uniquely identifies different entities within the
collection. The join_key property is typically used for joining entities
with their associated features. If not specified, defaults to the name.
Expand All @@ -48,7 +45,6 @@ class Entity:

name: str
value_type: ValueType
join_keys: List[str]
join_key: str
description: str
tags: Dict[str, str]
Expand Down Expand Up @@ -84,21 +80,17 @@ def __init__(
self.name = name
self.value_type = ValueType.UNKNOWN

# For now, both the `join_key` and `join_keys` attributes are set correctly,
# so both are usable.
# TODO(felixwang9817): Fully remove the usage of `join_key` throughout the codebase,
# at which point the `join_key` attribute no longer needs to be set.
if join_keys and len(join_keys) > 1:
# TODO(felixwang9817): When multiple join keys are supported, add a `join_keys` attribute
# and deprecate the `join_key` attribute.
raise ValueError(
"An entity may only have single join key. "
"An entity may only have a single join key. "
"Multiple join keys will be supported in the future."
)
elif join_keys and len(join_keys) == 1:
self.join_keys = join_keys
self.join_key = join_keys[0]
else:
self.join_key = self.name
self.join_keys = [self.join_key]

self.description = description
self.tags = tags if tags is not None else {}
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def __init__(
features: List[Field] = []
self.entity_columns = []

join_keys = []
join_keys: List[str] = []
if entities:
for entity in entities:
join_keys += entity.join_keys
join_keys.append(entity.join_key)

for field in self.schema:
if field.name in join_keys:
Expand Down
16 changes: 3 additions & 13 deletions sdk/python/feast/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ def update_feature_views_with_inferred_features_and_entities(
config: The config for the current feature store.
"""
entity_name_to_entity_map = {e.name: e for e in entities}
entity_name_to_join_keys_map = {e.name: e.join_keys for e in entities}
entity_name_to_join_key_map = {e.name: e.join_key for e in entities}

for fv in fvs:
join_keys = set(
[
join_key
for entity_name in fv.entities
for join_key in entity_name_to_join_keys_map[entity_name]
]
[entity_name_to_join_key_map[entity_name] for entity_name in fv.entities]
)

# Fields whose names match a join key are considered to be entity columns; all
Expand Down Expand Up @@ -164,13 +160,7 @@ def update_feature_views_with_inferred_features_and_entities(
fv.entity_columns.append(Field(name=DUMMY_ENTITY_ID, dtype=String))

# Run inference for entity columns if there are fewer entity fields than expected.
num_expected_join_keys = sum(
[
len(entity_name_to_join_keys_map[entity_name])
for entity_name in fv.entities
]
)
run_inference_for_entities = len(fv.entity_columns) < num_expected_join_keys
run_inference_for_entities = len(fv.entity_columns) < len(join_keys)

# Run inference for feature columns if there are no feature fields.
run_inference_for_features = len(fv.features) == 0
Expand Down

0 comments on commit 857876b

Please sign in to comment.