Skip to content

Commit 9eea070

Browse files
authored
FeatureStore, FeatureView, Config, and BIgQuerySource classes for updated SDK (#1364)
* FeatureView and FeatureStore classes Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Address comments and fix lint Signed-off-by: Jacob Klegar <jacob@tecton.ai> * remove unnecessary import Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Update docstrings per comments Signed-off-by: Jacob Klegar <jacob@tecton.ai> * Add docstring and address comment Signed-off-by: Jacob Klegar <jacob@tecton.ai>
1 parent 11dd8ee commit 9eea070

4 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2019 The Feast Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from typing import Dict, Optional
15+
16+
17+
class BigQuerySource:
18+
"""
19+
Represents a BigQuery table reference or BigQuery query that returns a set of features.
20+
"""
21+
22+
def __init__(
23+
self,
24+
table_ref: Optional[str],
25+
event_timestamp_column: str,
26+
created_timestamp_column: Optional[str],
27+
field_mapping: Optional[Dict[str, str]],
28+
query: Optional[str],
29+
):
30+
if (table_ref is None) != (query is None):
31+
raise Exception("Exactly one of table_ref and query should be specified")
32+
self.table_ref = table_ref
33+
self.event_timestamp_column = event_timestamp_column
34+
self.created_timestamp_column = created_timestamp_column
35+
self.field_mapping = field_mapping
36+
self.query = query
37+
return

‎sdk/python/feast/feature_store.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2019 The Feast Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from typing import Optional
15+
16+
from feast.feature_store_config import Config
17+
18+
19+
class FeatureStore:
20+
"""
21+
A FeatureStore object is used to define, create, and retrieve features.
22+
"""
23+
24+
def __init__(
25+
self, config_path: Optional[str], config: Optional[Config],
26+
):
27+
if config_path is None or config is None:
28+
raise Exception("You cannot specify both config_path and config")
29+
if config is not None:
30+
self.config = config
31+
elif config_path is not None:
32+
self.config = Config.from_path(config_path)
33+
else:
34+
self.config = Config()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2019 The Feast Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from typing import Optional
15+
16+
import yaml
17+
18+
19+
class Config:
20+
"""
21+
Configuration object that contains all possible configuration options for a FeatureStore.
22+
"""
23+
24+
def __init__(
25+
self,
26+
provider: Optional[str],
27+
online_store: Optional[str],
28+
metadata_store: Optional[str],
29+
):
30+
self.provider = provider if (provider is not None) else "local"
31+
self.online_store = online_store if (online_store is not None) else "local"
32+
self.metadata_store = (
33+
metadata_store if (metadata_store is not None) else "./metadata_store"
34+
)
35+
36+
@classmethod
37+
def from_path(cls, config_path: str):
38+
"""
39+
Construct the configuration object from a filepath containing a yaml file.
40+
41+
Example yaml file:
42+
43+
provider: gcp
44+
online_store: firestore
45+
metadata_store: gs://my_bucket/metadata_store
46+
"""
47+
with open(config_path, "r") as f:
48+
config_dict = yaml.safe_load(f)
49+
return cls(
50+
provider=config_dict.get("provider"),
51+
online_store=config_dict.get("online_store"),
52+
metadata_store=config_dict.get("metadata_store"),
53+
)

‎sdk/python/feast/feature_view.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2019 The Feast Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from datetime import datetime
15+
from typing import Dict, List
16+
17+
from feast.big_query_source import BigQuerySource
18+
from feast.entity import Entity
19+
from feast.feature import Feature
20+
21+
22+
class FeatureView:
23+
"""
24+
A FeatureView defines a logical grouping of servable features.
25+
"""
26+
27+
def __init__(
28+
self,
29+
name: str,
30+
entities: List[Entity],
31+
features: List[Feature],
32+
tags: Dict[str, str],
33+
ttl: str,
34+
online: bool,
35+
inputs: BigQuerySource,
36+
feature_start_time: datetime,
37+
):
38+
self.name = name
39+
self.entities = entities
40+
self.features = features
41+
self.tags = tags
42+
self.ttl = ttl
43+
self.online = online
44+
self.inputs = inputs
45+
self.feature_start_time = feature_start_time
46+
return

0 commit comments

Comments
 (0)