Skip to content

Commit 03dae13

Browse files
authored
feat: Added delete_table to redis online store (#3857)
* feat: Added delete_table to redis online store Signed-off-by: Jiwon Park <[email protected]> * fix: Fix hdel params to *args Signed-off-by: Jiwon Park <[email protected]> --------- Signed-off-by: Jiwon Park <[email protected]>
1 parent 64459ad commit 03dae13

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

  • sdk/python/feast/infra/online_stores

‎sdk/python/feast/infra/online_stores/redis.py‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ def delete_entity_values(self, config: RepoConfig, join_keys: List[str]):
106106

107107
logger.debug(f"Deleted {deleted_count} rows for entity {', '.join(join_keys)}")
108108

109+
def delete_table(self, config: RepoConfig, table: FeatureView):
110+
"""
111+
Delete all rows in Redis for a specific feature view
112+
113+
Args:
114+
config: Feast config
115+
table: Feature view to delete
116+
"""
117+
client = self._get_client(config.online_store)
118+
deleted_count = 0
119+
prefix = _redis_key_prefix(table.join_keys)
120+
121+
redis_hash_keys = [_mmh3(f"{table.name}:{f.name}") for f in table.features]
122+
redis_hash_keys.append(bytes(f"_ts:{table.name}", "utf8"))
123+
124+
with client.pipeline(transaction=False) as pipe:
125+
for _k in client.scan_iter(
126+
b"".join([prefix, b"*", config.project.encode("utf8")])
127+
):
128+
_tables = {
129+
_hk[4:] for _hk in client.hgetall(_k) if _hk.startswith(b"_ts:")
130+
}
131+
if bytes(table.name, "utf8") not in _tables:
132+
continue
133+
if len(_tables) == 1:
134+
pipe.delete(_k)
135+
else:
136+
pipe.hdel(_k, *redis_hash_keys)
137+
deleted_count += 1
138+
pipe.execute()
139+
140+
logger.debug(f"Deleted {deleted_count} rows for feature view {table.name}")
141+
109142
@log_exceptions_and_usage(online_store="redis")
110143
def update(
111144
self,
@@ -117,16 +150,19 @@ def update(
117150
partial: bool,
118151
):
119152
"""
120-
Look for join_keys (list of entities) that are not in use anymore
121-
(usually this happens when the last feature view that was using specific compound key is deleted)
122-
and remove all features attached to this "join_keys".
153+
Delete data from feature views that are no longer in use.
154+
155+
Args:
156+
config: Feast config
157+
tables_to_delete: Feature views to delete
158+
tables_to_keep: Feature views to keep
159+
entities_to_delete: Entities to delete
160+
entities_to_keep: Entities to keep
161+
partial: Whether to do a partial update
123162
"""
124-
join_keys_to_keep = set(tuple(table.join_keys) for table in tables_to_keep)
125163

126-
join_keys_to_delete = set(tuple(table.join_keys) for table in tables_to_delete)
127-
128-
for join_keys in join_keys_to_delete - join_keys_to_keep:
129-
self.delete_entity_values(config, list(join_keys))
164+
for table in tables_to_delete:
165+
self.delete_table(config, table)
130166

131167
def teardown(
132168
self,

0 commit comments

Comments
 (0)