forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference.py
More file actions
56 lines (47 loc) · 2.28 KB
/
Copy pathinference.py
File metadata and controls
56 lines (47 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from typing import List
from feast import Entity
from feast.feature_view import FeatureView
from feast.value_type import ValueType
def infer_entity_value_type_from_feature_views(
entities: List[Entity], feature_views: List[FeatureView]
) -> List[Entity]:
"""
Infer entity value type by examining schema of feature view input sources
"""
incomplete_entities = {
entity.name: entity
for entity in entities
if entity.value_type == ValueType.UNKNOWN
}
incomplete_entities_keys = incomplete_entities.keys()
for view in feature_views:
if not (incomplete_entities_keys & set(view.entities)):
continue # skip if view doesn't contain any entities that need inference
col_names_and_types = view.input.get_table_column_names_and_types()
for entity_name in view.entities:
if entity_name in incomplete_entities:
# get entity information from information extracted from the view input source
extracted_entity_name_type_pairs = list(
filter(lambda tup: tup[0] == entity_name, col_names_and_types)
)
if len(extracted_entity_name_type_pairs) == 0:
# Doesn't mention inference error because would also be an error without inferencing
raise ValueError(
f"""No column in the input source for the {view.name} feature view matches
its entity's name."""
)
entity = incomplete_entities[entity_name]
inferred_value_type = view.input.source_datatype_to_feast_value_type()(
extracted_entity_name_type_pairs[0][1]
)
if (
entity.value_type != ValueType.UNKNOWN
and entity.value_type != inferred_value_type
) or (len(extracted_entity_name_type_pairs) > 1):
raise ValueError(
f"""Entity value_type inference failed for {entity_name} entity.
Multiple viable matches. Please explicitly specify the entity value_type
for this entity."""
)
entity.value_type = inferred_value_type
return entities