Skip to content

Commit

Permalink
Add test to ensure saving and loading from registry is safe (#1453)
Browse files Browse the repository at this point in the history
Signed-off-by: Willem Pienaar <git@willem.co>
  • Loading branch information
woop authored Apr 11, 2021
1 parent ec9c4fd commit 6304284
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 200 deletions.
24 changes: 14 additions & 10 deletions sdk/python/feast/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,13 @@ def __eq__(self, other):
if not isinstance(other, FileSource):
raise TypeError("Comparisons should only involve FileSource class objects.")

if (
self.file_options.file_url != other.file_options.file_url
or self.file_options.file_format != other.file_options.file_format
):
return False
return True
return (
self.file_options.file_url == other.file_options.file_url
and self.file_options.file_format == other.file_options.file_format
and self.event_timestamp_column == other.event_timestamp_column
and self.created_timestamp_column == other.created_timestamp_column
and self.field_mapping == other.field_mapping
)

@property
def file_options(self):
Expand Down Expand Up @@ -633,10 +634,13 @@ def __eq__(self, other):
"Comparisons should only involve BigQuerySource class objects."
)

if self.bigquery_options.table_ref != other.bigquery_options.table_ref:
return False

return True
return (
self.bigquery_options.table_ref == other.bigquery_options.table_ref
and self.bigquery_options.query == other.bigquery_options.query
and self.event_timestamp_column == other.event_timestamp_column
and self.created_timestamp_column == other.created_timestamp_column
and self.field_mapping == other.field_mapping
)

@property
def table_ref(self):
Expand Down
34 changes: 34 additions & 0 deletions sdk/python/feast/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Dict, List, Optional, Tuple, Union

from google.protobuf.duration_pb2 import Duration
from google.protobuf.json_format import MessageToJson
from google.protobuf.timestamp_pb2 import Timestamp

from feast import utils
Expand Down Expand Up @@ -82,6 +83,39 @@ def __init__(

self.materialization_intervals = []

def __repr__(self):
items = (f"{k} = {v}" for k, v in self.__dict__.items())
return f"<{self.__class__.__name__}({', '.join(items)})>"

def __str__(self):
return str(MessageToJson(self.to_proto()))

def __hash__(self):
return hash(self.name)

def __eq__(self, other):
if not isinstance(other, FeatureView):
raise TypeError(
"Comparisons should only involve FeatureView class objects."
)

if (
self.tags != other.tags
or self.name != other.name
or self.ttl != other.ttl
or self.online != other.online
):
return False

if sorted(self.entities) != sorted(other.entities):
return False
if sorted(self.features) != sorted(other.features):
return False
if self.input != other.input:
return False

return True

def is_valid(self):
"""
Validates the state of a feature view locally. Raises an exception
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/feast/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def __init__(self):

@property
def telemetry_id(self):
if os.environ["FEAST_FORCE_TELEMETRY_UUID"]:
return os.environ["FEAST_FORCE_TELEMETRY_UUID"]
if os.getenv("FEAST_FORCE_TELEMETRY_UUID"):
return os.getenv("FEAST_FORCE_TELEMETRY_UUID")
return self._telemetry_id

def log(self, function_name: str):
Expand Down
Loading

0 comments on commit 6304284

Please sign in to comment.