-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfeature_views.py
More file actions
116 lines (98 loc) · 3.04 KB
/
feature_views.py
File metadata and controls
116 lines (98 loc) · 3.04 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import click
import yaml
from feast import utils
from feast.cli.cli_options import tagsOption
from feast.errors import FeastObjectNotFoundException
from feast.feature_view import FeatureView
from feast.on_demand_feature_view import OnDemandFeatureView
from feast.repo_operations import create_feature_store
@click.group(name="feature-views")
def feature_views_cmd():
"""
Access feature views
"""
pass
@feature_views_cmd.command("describe")
@click.argument("name", type=click.STRING)
@click.pass_context
def feature_view_describe(ctx: click.Context, name: str):
"""
Describe a feature view
"""
store = create_feature_store(ctx)
try:
feature_view = store.get_feature_view(name)
except FeastObjectNotFoundException as e:
print(e)
exit(1)
print(
yaml.dump(
yaml.safe_load(str(feature_view)), default_flow_style=False, sort_keys=False
)
)
@feature_views_cmd.command(name="list")
@tagsOption
@click.pass_context
def feature_view_list(ctx: click.Context, tags: list[str]):
"""
List all feature views
"""
store = create_feature_store(ctx)
table = []
tags_filter = utils.tags_list_to_dict(tags)
for feature_view in [
*store.list_batch_feature_views(tags=tags_filter),
*store.list_on_demand_feature_views(tags=tags_filter),
]:
entities = set()
if isinstance(feature_view, FeatureView):
entities.update(feature_view.entities)
elif isinstance(feature_view, OnDemandFeatureView):
for backing_fv in feature_view.source_feature_view_projections.values():
entities.update(store.get_feature_view(backing_fv.name).entities)
table.append(
[
feature_view.name,
entities if len(entities) > 0 else "n/a",
type(feature_view).__name__,
]
)
from tabulate import tabulate
print(tabulate(table, headers=["NAME", "ENTITIES", "TYPE"], tablefmt="plain"))
@feature_views_cmd.command("list-versions")
@click.argument("name", type=click.STRING)
@click.pass_context
def feature_view_versions(ctx: click.Context, name: str):
"""
List version history for a feature view
"""
store = create_feature_store(ctx)
try:
versions = store.list_feature_view_versions(name)
except NotImplementedError:
print("Version history is not supported by this registry backend.")
exit(1)
except Exception as e:
print(e)
exit(1)
if not versions:
print(f"No version history found for feature view '{name}'.")
return
table = []
for v in versions:
table.append(
[
v["version"],
v["feature_view_type"],
str(v["created_timestamp"]),
v["version_id"],
]
)
from tabulate import tabulate
print(
tabulate(
table,
headers=["VERSION", "TYPE", "CREATED", "VERSION_ID"],
tablefmt="plain",
)
)