|
1 | | -# HANA Translator/query constructor |
2 | 1 | import logging |
3 | | -from typing import Any, Dict, List, Tuple, Union |
4 | | - |
5 | | -from langchain_core.structured_query import ( |
6 | | - Comparator, |
7 | | - Comparison, |
8 | | - Operation, |
9 | | - Operator, |
10 | | - StructuredQuery, |
11 | | - Visitor, |
12 | | -) |
| 2 | +from typing import List, Tuple, Any |
13 | 3 |
|
14 | 4 | logger = logging.getLogger(__name__) |
15 | 5 |
|
@@ -49,53 +39,6 @@ def __repr__(self) -> None: # type: ignore[override] |
49 | 39 |
|
50 | 40 | LOGICAL_OPERATORS_TO_SQL = {"$and": "AND", "$or": "OR"} |
51 | 41 |
|
52 | | - |
53 | | -class HanaTranslator(Visitor): |
54 | | - """ |
55 | | - Translate internal query language elements to valid filters params for |
56 | | - HANA vectorstore. |
57 | | - """ |
58 | | - |
59 | | - allowed_operators = [Operator.AND, Operator.OR] |
60 | | - """Subset of allowed logical operators.""" |
61 | | - allowed_comparators = [ |
62 | | - Comparator.EQ, |
63 | | - Comparator.NE, |
64 | | - Comparator.GT, |
65 | | - Comparator.LT, |
66 | | - Comparator.GTE, |
67 | | - Comparator.LTE, |
68 | | - Comparator.IN, |
69 | | - Comparator.NIN, |
70 | | - Comparator.CONTAIN, |
71 | | - Comparator.LIKE, |
72 | | - ] |
73 | | - |
74 | | - def _format_func(self, func: Union[Operator, Comparator]) -> str: |
75 | | - self._validate_func(func) |
76 | | - return f"${'contains' if func == Comparator.CONTAIN else func.value}" |
77 | | - |
78 | | - def visit_operation(self, operation: Operation) -> Dict: |
79 | | - args = [arg.accept(self) for arg in operation.arguments] |
80 | | - return {self._format_func(operation.operator): args} |
81 | | - |
82 | | - def visit_comparison(self, comparison: Comparison) -> Dict: |
83 | | - return { |
84 | | - comparison.attribute: { |
85 | | - self._format_func(comparison.comparator): comparison.value |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - def visit_structured_query( |
90 | | - self, structured_query: StructuredQuery |
91 | | - ) -> Tuple[str, dict]: |
92 | | - if structured_query.filter is None: |
93 | | - kwargs = {} |
94 | | - else: |
95 | | - kwargs = {"filter": structured_query.filter.accept(self)} |
96 | | - return structured_query.query, kwargs |
97 | | - |
98 | | - |
99 | 42 | class CreateWhereClause: |
100 | 43 | def __init__(self, hanaDb: Any) -> None: |
101 | 44 | self.specific_metadata_columns = hanaDb.specific_metadata_columns |
|
0 commit comments