Skip to content

Commit

Permalink
Initialize Datastore client in __init__
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Wang <[email protected]>
  • Loading branch information
felixwang9817 committed Dec 14, 2021
1 parent 0bc433a commit fad30d4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sdk/python/feast/infra/online_stores/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,14 @@ class DatastoreTable(InfraObject):
name: The name of the table.
project_id (optional): The GCP project id.
namespace (optional): Datastore namespace.
client: Datastore client.
"""

project: str
name: str
project_id: Optional[str]
namespace: Optional[str]
client: datastore.Client

def __init__(
self,
Expand All @@ -314,6 +316,7 @@ def __init__(
self.name = name
self.project_id = project_id
self.namespace = namespace
self.client = _initialize_client(self.project_id, self.namespace)

def to_proto(self) -> InfraObjectProto:
datastore_table_proto = DatastoreTableProto()
Expand Down Expand Up @@ -348,18 +351,16 @@ def from_proto(infra_object_proto: InfraObjectProto) -> Any:
return datastore_table

def update(self):
client = _initialize_client(self.project_id, self.namespace)
key = client.key("Project", self.project, "Table", self.name)
key = self.client.key("Project", self.project, "Table", self.name)
entity = datastore.Entity(
key=key, exclude_from_indexes=("created_ts", "event_ts", "values")
)
entity.update({"created_ts": datetime.utcnow()})
client.put(entity)
self.client.put(entity)

def teardown(self):
client = _initialize_client(self.project_id, self.namespace)
key = client.key("Project", self.project, "Table", self.name)
_delete_all_values(client, key)
key = self.client.key("Project", self.project, "Table", self.name)
_delete_all_values(self.client, key)

# Delete the table metadata datastore entity
client.delete(key)
self.client.delete(key)

0 comments on commit fad30d4

Please sign in to comment.