Skip to content

Commit

Permalink
refactor!: Remove deprecated parameters from Entity and FeatureView (#…
Browse files Browse the repository at this point in the history
…2427)

* Remove labels parameter from Entity

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

* Remove input parameter and deprecate Duration type for ttl parameter in FeatureView

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

* Change examples to stop using Duration

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

* Delete unused example feature repo

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

* Format

Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 authored Mar 21, 2022
1 parent e7dd4b7 commit e0041f1
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 101 deletions.
20 changes: 2 additions & 18 deletions sdk/python/feast/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
from datetime import datetime
from typing import Dict, Optional

Expand All @@ -23,8 +22,6 @@
from feast.usage import log_exceptions
from feast.value_type import ValueType

warnings.simplefilter("once", DeprecationWarning)


class Entity:
"""
Expand Down Expand Up @@ -61,28 +58,15 @@ def __init__(
value_type: ValueType = ValueType.UNKNOWN,
description: str = "",
join_key: Optional[str] = None,
tags: Dict[str, str] = None,
labels: Optional[Dict[str, str]] = None,
tags: Optional[Dict[str, str]] = None,
owner: str = "",
):
"""Creates an Entity object."""
self.name = name
self.value_type = value_type
self.join_key = join_key if join_key else name
self.description = description

if labels is not None:
self.tags = labels
warnings.warn(
(
"The parameter 'labels' is being deprecated. Please use 'tags' instead. "
"Feast 0.20 and onwards will not support the parameter 'labels'."
),
DeprecationWarning,
)
else:
self.tags = labels or tags or {}

self.tags = tags if tags is not None else {}
self.owner = owner
self.created_timestamp = None
self.last_updated_timestamp = None
Expand Down
41 changes: 17 additions & 24 deletions sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class FeatureView(BaseFeatureView):
ttl: The amount of time this group of features lives. A ttl of 0 indicates that
this group of features lives forever. Note that large ttl's or a ttl of 0
can result in extremely computationally intensive queries.
input: The source of data where this group of features is stored.
batch_source (optional): The batch source of data where this group of features
is stored.
batch_source: The batch source of data where this group of features is stored.
stream_source (optional): The stream source of data where this group of features
is stored.
features (optional): The set of features defined as part of this FeatureView.
Expand All @@ -72,7 +70,6 @@ class FeatureView(BaseFeatureView):
tags: Optional[Dict[str, str]]
ttl: timedelta
online: bool
input: DataSource
batch_source: DataSource
stream_source: Optional[DataSource]
materialization_intervals: List[Tuple[datetime, datetime]]
Expand All @@ -83,8 +80,7 @@ def __init__(
name: str,
entities: List[str],
ttl: Union[Duration, timedelta],
input: Optional[DataSource] = None,
batch_source: Optional[DataSource] = None,
batch_source: DataSource,
stream_source: Optional[DataSource] = None,
features: Optional[List[Feature]] = None,
tags: Optional[Dict[str, str]] = None,
Expand All @@ -96,26 +92,17 @@ def __init__(
Raises:
ValueError: A field mapping conflicts with an Entity or a Feature.
"""
if input is not None:
warnings.warn(
(
"The argument 'input' is being deprecated. Please use 'batch_source' "
"instead. Feast 0.13 and onwards will not support the argument 'input'."
),
DeprecationWarning,
)

_input = input or batch_source
assert _input is not None

_features = features or []

cols = [entity for entity in entities] + [feat.name for feat in _features]
for col in cols:
if _input.field_mapping is not None and col in _input.field_mapping.keys():
if (
batch_source.field_mapping is not None
and col in batch_source.field_mapping.keys()
):
raise ValueError(
f"The field {col} is mapped to {_input.field_mapping[col]} for this data source. "
f"Please either remove this field mapping or use {_input.field_mapping[col]} as the "
f"The field {col} is mapped to {batch_source.field_mapping[col]} for this data source. "
f"Please either remove this field mapping or use {batch_source.field_mapping[col]} as the "
f"Entity or Feature name."
)

Expand All @@ -125,12 +112,19 @@ def __init__(

if isinstance(ttl, Duration):
self.ttl = timedelta(seconds=int(ttl.seconds))
warnings.warn(
(
"The option to pass a Duration object to the ttl parameter is being deprecated. "
"Please pass a timedelta object instead. Feast 0.21 and onwards will not support "
"Duration objects."
),
DeprecationWarning,
)
else:
self.ttl = ttl

self.online = online
self.input = _input
self.batch_source = _input
self.batch_source = batch_source
self.stream_source = stream_source

self.materialization_intervals = []
Expand All @@ -144,7 +138,6 @@ def __copy__(self):
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,
Expand Down
10 changes: 5 additions & 5 deletions sdk/python/feast/infra/offline_stores/offline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_feature_view_query_context(
join_keys = []
entity_selections = []
reverse_field_mapping = {
v: k for k, v in feature_view.input.field_mapping.items()
v: k for k, v in feature_view.batch_source.field_mapping.items()
}
for entity_name in feature_view.entities:
entity = registry.get_entity(entity_name, project)
Expand All @@ -130,8 +130,8 @@ def get_feature_view_query_context(
else:
ttl_seconds = 0

event_timestamp_column = feature_view.input.event_timestamp_column
created_timestamp_column = feature_view.input.created_timestamp_column
event_timestamp_column = feature_view.batch_source.event_timestamp_column
created_timestamp_column = feature_view.batch_source.created_timestamp_column

min_event_timestamp = None
if feature_view.ttl:
Expand All @@ -148,15 +148,15 @@ def get_feature_view_query_context(
features=[
reverse_field_mapping.get(feature, feature) for feature in features
],
field_mapping=feature_view.input.field_mapping,
field_mapping=feature_view.batch_source.field_mapping,
event_timestamp_column=reverse_field_mapping.get(
event_timestamp_column, event_timestamp_column
),
created_timestamp_column=reverse_field_mapping.get(
created_timestamp_column, created_timestamp_column
),
# TODO: Make created column optional and not hardcoded
table_subquery=feature_view.input.get_table_query_string(),
table_subquery=feature_view.batch_source.get_table_query_string(),
entity_selections=entity_selections,
min_event_timestamp=min_event_timestamp,
max_event_timestamp=max_event_timestamp,
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/feast/templates/local/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an example feature definition file

from google.protobuf.duration_pb2 import Duration
from datetime import timedelta

from feast import Entity, Feature, FeatureView, FileSource, ValueType

Expand All @@ -23,7 +23,7 @@
driver_hourly_stats_view = FeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
ttl=Duration(seconds=86400 * 1),
ttl=timedelta(days=1),
features=[
Feature(name="conv_rate", dtype=ValueType.FLOAT),
Feature(name="acc_rate", dtype=ValueType.FLOAT),
Expand Down
7 changes: 3 additions & 4 deletions sdk/python/feast/templates/spark/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# This is an example feature definition file #
# # # # # # # # # # # # # # # # # # # # # # # #

from datetime import timedelta
from pathlib import Path

from google.protobuf.duration_pb2 import Duration

from feast import Entity, Feature, FeatureView, ValueType
from feast.infra.offline_stores.contrib.spark_offline_store.spark_source import (
SparkSource,
Expand Down Expand Up @@ -41,7 +40,7 @@
driver_hourly_stats_view = FeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
ttl=Duration(seconds=86400 * 7), # one week
ttl=timedelta(days=7),
features=[
Feature(name="conv_rate", dtype=ValueType.FLOAT),
Feature(name="acc_rate", dtype=ValueType.FLOAT),
Expand All @@ -54,7 +53,7 @@
customer_daily_profile_view = FeatureView(
name="customer_daily_profile",
entities=["customer_id"],
ttl=Duration(seconds=86400 * 7), # one week
ttl=timedelta(days=7),
features=[
Feature(name="current_balance", dtype=ValueType.FLOAT),
Feature(name="avg_passenger_count", dtype=ValueType.FLOAT),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from google.protobuf.duration_pb2 import Duration
from datetime import timedelta

from feast import FeatureView, FileSource

Expand All @@ -11,7 +11,7 @@
entities=["driver_id"],
online=False,
batch_source=driver_hourly_stats,
ttl=Duration(seconds=10),
ttl=timedelta(days=1),
tags={},
)

Expand All @@ -20,6 +20,6 @@
entities=["driver_id"],
online=False,
batch_source=driver_hourly_stats,
ttl=Duration(seconds=10),
ttl=timedelta(days=1),
tags={},
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from google.protobuf.duration_pb2 import Duration
from datetime import timedelta

from feast import Entity, Feature, FeatureView, FileSource, ValueType

Expand All @@ -21,7 +21,7 @@
driver_hourly_stats_view = FeatureView(
name="driver_hourly_stats",
entities=["driver_id"],
ttl=Duration(seconds=86400 * 1),
ttl=timedelta(days=1),
features=[
Feature(name="conv_rate", dtype=ValueType.FLOAT),
Feature(name="acc_rate", dtype=ValueType.FLOAT),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ def get_expected_training_df(
(
f"field_mapping__{feature}" if full_feature_names else feature
): field_mapping_record.get(column, None)
for (column, feature) in field_mapping_fv.input.field_mapping.items()
for (
column,
feature,
) in field_mapping_fv.batch_source.field_mapping.items()
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import timedelta

import pytest
from google.protobuf.duration_pb2 import Duration

from feast import BigQuerySource, Feature, FeatureView, ValueType
from tests.utils.cli_utils import CliRunner, get_example_repo
Expand Down Expand Up @@ -27,7 +28,7 @@ def test_partial() -> None:
driver_locations_100 = FeatureView(
name="driver_locations_100",
entities=["driver"],
ttl=Duration(seconds=86400 * 1),
ttl=timedelta(days=1),
features=[
Feature(name="lat", dtype=ValueType.FLOAT),
Feature(name="lon", dtype=ValueType.STRING),
Expand Down

0 comments on commit e0041f1

Please sign in to comment.