Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/memos/graph_dbs/polardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4686,8 +4686,10 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) {sql_op} '\"{escaped_value}\"'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(op_value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) {sql_op} {op_value}::agtype"
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}')"
)
else:
# Direct property access (e.g., "created_at" is directly in properties, not in properties.info)
Expand All @@ -4697,8 +4699,10 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} '\"{escaped_value}\"'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(op_value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} {op_value}::agtype"
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) {sql_op} ag_catalog.agtype_in('{value_json}')"
)
elif op == "=":
# Handle equality operator
Expand Down Expand Up @@ -4739,8 +4743,10 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '[{op_value}]'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(op_value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = {op_value}::agtype"
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = ag_catalog.agtype_in('{value_json}')"
)
else:
# Direct property access
Expand All @@ -4767,17 +4773,21 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '{json_array}'::agtype"
)
else:
# For non-string list values, convert to JSON string and then to agtype
value_json = json.dumps(op_value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {op_value}::agtype"
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
)
else:
if key in ("tags", "sources"):
condition_parts.append(
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '[{op_value}]'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(op_value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {op_value}::agtype"
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
)
elif op == "contains":
# Handle contains operator
Expand Down Expand Up @@ -4962,8 +4972,10 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '\"{escaped_value}\"'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = '\"{value}\"'::agtype"
f"ag_catalog.agtype_access_operator(VARIADIC ARRAY[properties, '\"info\"'::ag_catalog.agtype, '\"{info_field}\"'::ag_catalog.agtype]) = ag_catalog.agtype_in('{value_json}')"
)
else:
# Direct property access (simple equality)
Expand All @@ -4973,8 +4985,10 @@ def build_filter_condition(condition_dict: dict) -> str:
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = '\"{escaped_value}\"'::agtype"
)
else:
# For non-string values (numbers, booleans, etc.), convert to JSON string and then to agtype
value_json = json.dumps(value)
condition_parts.append(
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = {value}::agtype"
f"ag_catalog.agtype_access_operator(properties, '\"{key}\"'::agtype) = ag_catalog.agtype_in('{value_json}')"
)
return " AND ".join(condition_parts)

Expand Down