Skip to content

Commit c0b7228

Browse files
authored
feat: _build_filter_conditions_sql filter (#813)
1 parent c152f44 commit c0b7228

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/memos/graph_dbs/polardb.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,8 +4686,10 @@ def build_filter_condition(condition_dict: dict) -> str:
46864686
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) {sql_op} '\"{escaped_value}\"'::agtype"
46874687
)
46884688
else:
4689+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4690+
value_json = json.dumps(op_value)
46894691
condition_parts.append(
4690-
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) {sql_op} {op_value}::agtype"
4692+
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) {sql_op} ag_catalog.agtype_in('{value_json}')"
46914693
)
46924694
else:
46934695
# Direct property access (e.g., "created_at" is directly in properties, not in properties.info)
@@ -4697,8 +4699,10 @@ def build_filter_condition(condition_dict: dict) -> str:
46974699
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} '\"{escaped_value}\"'::agtype"
46984700
)
46994701
else:
4702+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4703+
value_json = json.dumps(op_value)
47004704
condition_parts.append(
4701-
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} {op_value}::agtype"
4705+
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} ag_catalog.agtype_in('{value_json}')"
47024706
)
47034707
elif op == "=":
47044708
# Handle equality operator
@@ -4739,8 +4743,10 @@ def build_filter_condition(condition_dict: dict) -> str:
47394743
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '[{op_value}]'::agtype"
47404744
)
47414745
else:
4746+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4747+
value_json = json.dumps(op_value)
47424748
condition_parts.append(
4743-
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = {op_value}::agtype"
4749+
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = ag_catalog.agtype_in('{value_json}')"
47444750
)
47454751
else:
47464752
# Direct property access
@@ -4767,17 +4773,21 @@ def build_filter_condition(condition_dict: dict) -> str:
47674773
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '{json_array}'::agtype"
47684774
)
47694775
else:
4776+
# For non-string list values, convert to JSON string and then to agtype
4777+
value_json = json.dumps(op_value)
47704778
condition_parts.append(
4771-
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {op_value}::agtype"
4779+
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
47724780
)
47734781
else:
47744782
if key in ("tags", "sources"):
47754783
condition_parts.append(
47764784
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '[{op_value}]'::agtype"
47774785
)
47784786
else:
4787+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4788+
value_json = json.dumps(op_value)
47794789
condition_parts.append(
4780-
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {op_value}::agtype"
4790+
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
47814791
)
47824792
elif op == "contains":
47834793
# Handle contains operator
@@ -4962,8 +4972,10 @@ def build_filter_condition(condition_dict: dict) -> str:
49624972
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '\"{escaped_value}\"'::agtype"
49634973
)
49644974
else:
4975+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4976+
value_json = json.dumps(value)
49654977
condition_parts.append(
4966-
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '\"{value}\"'::agtype"
4978+
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = ag_catalog.agtype_in('{value_json}')"
49674979
)
49684980
else:
49694981
# Direct property access (simple equality)
@@ -4973,8 +4985,10 @@ def build_filter_condition(condition_dict: dict) -> str:
49734985
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '\"{escaped_value}\"'::agtype"
49744986
)
49754987
else:
4988+
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
4989+
value_json = json.dumps(value)
49764990
condition_parts.append(
4977-
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {value}::agtype"
4991+
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
49784992
)
49794993
return " AND ".join(condition_parts)
49804994

0 commit comments

Comments
 (0)