Skip to content

Commit e01aa66

Browse files
committed
initial import: adding fixes
1 parent cfa014f commit e01aa66

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • integrations/arcadedb/src/haystack_integrations/document_stores/arcadedb

integrations/arcadedb/src/haystack_integrations/document_stores/arcadedb/filters.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
"""Convert Haystack filter dictionaries to ArcadeDB SQL WHERE clauses."""
6-
6+
import re
77
from typing import Any
88

99

@@ -64,6 +64,12 @@ def _parse_condition(condition: dict[str, Any]) -> str:
6464

6565

6666
def _comparison_to_sql(field: str, operator: str, value: Any) -> str:
67+
68+
if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_.\[\]"]*$', field):
69+
msg = (f"Invalid field name: {field}. Field names must start with a letter or underscore and can contain "
70+
f"letters, digits, underscores, dots, brackets, and quotes.")
71+
raise ValueError(msg)
72+
6773
if operator == "==":
6874
if value is None:
6975
return f"{field} IS NULL"
@@ -106,7 +112,7 @@ def _comparison_to_sql(field: str, operator: str, value: Any) -> str:
106112
def _sql_value(value: Any) -> str:
107113
"""Format a Python value as an ArcadeDB SQL literal."""
108114
if isinstance(value, str):
109-
escaped = value.replace("'", "\\'")
115+
escaped = value.replace("\\", "\\\\").replace("'", "\\'")
110116
return f"'{escaped}'"
111117
if isinstance(value, bool):
112118
return "true" if value else "false"

0 commit comments

Comments
 (0)