Skip to content

Commit ef34979

Browse files
committed
Fix SingleStore teardown LIKE escaping
Signed-off-by: antznette1 <[email protected]>
1 parent dedb904 commit ef34979

File tree

1 file changed

+12
-6
lines changed
  • sdk/python/feast/infra/online_stores/singlestore_online_store

1 file changed

+12
-6
lines changed

sdk/python/feast/infra/online_stores/singlestore_online_store/singlestore.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import absolute_import
22

3+
import logging
34
from collections import defaultdict
45
from datetime import datetime
5-
import logging
66
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple
77

88
import singlestoredb
@@ -211,7 +211,7 @@ def update(
211211
event_ts timestamp NULL DEFAULT NULL,
212212
created_ts timestamp NULL DEFAULT NULL,
213213
PRIMARY KEY(entity_key, feature_name),
214-
INDEX {_quote_identifier(table_name + '_ek')} (entity_key))"""
214+
INDEX {_quote_identifier(table_name + "_ek")} (entity_key))"""
215215
)
216216

217217
for table in tables_to_delete:
@@ -313,16 +313,22 @@ def _quote_identifier(identifier: str) -> str:
313313
return f"`{escaped}`"
314314

315315

316-
def _drop_discovered_versioned_tables(cur: Cursor, project: str, table: FeatureView) -> None:
316+
def _drop_discovered_versioned_tables(
317+
cur: Cursor, project: str, table: FeatureView
318+
) -> None:
317319
base_table_name = online_store_table_id(project, table, enable_versioning=False)
318-
like_pattern = f"{base_table_name}_v%"
320+
escaped_base_table_name = base_table_name.replace("\\", "\\\\")
321+
escaped_base_table_name = escaped_base_table_name.replace("%", "\\%")
322+
escaped_base_table_name = escaped_base_table_name.replace("_", "\\_")
323+
like_pattern = f"{escaped_base_table_name}\\_v%"
319324
try:
320-
cur.execute("SHOW TABLES LIKE %s", (like_pattern,))
325+
cur.execute("SHOW TABLES LIKE %s ESCAPE '\\\\'", (like_pattern,))
321326
rows = cur.fetchall() or []
322327
for row in rows:
323328
table_name = row[0]
329+
index_name = f"{table_name}_ek"
324330
cur.execute(
325-
f"DROP INDEX IF EXISTS {_quote_identifier(table_name + '_ek')} ON {_quote_identifier(table_name)};"
331+
f"DROP INDEX IF EXISTS {_quote_identifier(index_name)} ON {_quote_identifier(table_name)};"
326332
)
327333
cur.execute(f"DROP TABLE IF EXISTS {_quote_identifier(table_name)}")
328334
except Exception as e:

0 commit comments

Comments
 (0)