Skip to content

Commit 426a307

Browse files
committed
feat: fix polardb edges
1 parent 49ccf08 commit 426a307

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

src/memos/graph_dbs/polardb.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,24 +1776,39 @@ def export_graph(
17761776

17771777
for row in edge_results:
17781778
source_agtype, target_agtype, edge_agtype = row
1779+
1780+
# Extract and clean source
1781+
source_raw = source_agtype.value if hasattr(source_agtype, "value") else str(source_agtype)
1782+
if isinstance(source_raw, str) and source_raw.startswith('"') and source_raw.endswith('"'):
1783+
source = source_raw[1:-1]
1784+
else:
1785+
source = str(source_raw)
1786+
1787+
# Extract and clean target
1788+
target_raw = target_agtype.value if hasattr(target_agtype, "value") else str(target_agtype)
1789+
if isinstance(target_raw, str) and target_raw.startswith('"') and target_raw.endswith('"'):
1790+
target = target_raw[1:-1]
1791+
else:
1792+
target = str(target_raw)
1793+
1794+
# Extract and clean edge type
1795+
type_raw = edge_agtype.value if hasattr(edge_agtype, "value") else str(edge_agtype)
1796+
if isinstance(type_raw, str) and type_raw.startswith('"') and type_raw.endswith('"'):
1797+
edge_type = type_raw[1:-1]
1798+
else:
1799+
edge_type = str(type_raw)
1800+
17791801
edges.append(
17801802
{
1781-
"source": source_agtype.value
1782-
if hasattr(source_agtype, "value")
1783-
else str(source_agtype),
1784-
"target": target_agtype.value
1785-
if hasattr(target_agtype, "value")
1786-
else str(target_agtype),
1787-
"type": edge_agtype.value
1788-
if hasattr(edge_agtype, "value")
1789-
else str(edge_agtype),
1803+
"source": source,
1804+
"target": target,
1805+
"type": edge_type,
17901806
}
17911807
)
17921808

17931809
except Exception as e:
17941810
logger.error(f"[EXPORT GRAPH - EDGES] Exception: {e}", exc_info=True)
17951811
raise RuntimeError(f"[EXPORT GRAPH - EDGES] Exception: {e}") from e
1796-
17971812
return {"nodes": nodes, "edges": edges}
17981813

17991814
@timed
@@ -2765,9 +2780,26 @@ def get_edges(
27652780

27662781
edges = []
27672782
for row in results:
2768-
from_id = row[0].value if hasattr(row[0], "value") else row[0]
2769-
to_id = row[1].value if hasattr(row[1], "value") else row[1]
2770-
edge_type = row[2].value if hasattr(row[2], "value") else row[2]
2783+
# Extract and clean from_id
2784+
from_id_raw = row[0].value if hasattr(row[0], "value") else row[0]
2785+
if isinstance(from_id_raw, str) and from_id_raw.startswith('"') and from_id_raw.endswith('"'):
2786+
from_id = from_id_raw[1:-1]
2787+
else:
2788+
from_id = str(from_id_raw)
2789+
2790+
# Extract and clean to_id
2791+
to_id_raw = row[1].value if hasattr(row[1], "value") else row[1]
2792+
if isinstance(to_id_raw, str) and to_id_raw.startswith('"') and to_id_raw.endswith('"'):
2793+
to_id = to_id_raw[1:-1]
2794+
else:
2795+
to_id = str(to_id_raw)
2796+
2797+
# Extract and clean edge_type
2798+
edge_type_raw = row[2].value if hasattr(row[2], "value") else row[2]
2799+
if isinstance(edge_type_raw, str) and edge_type_raw.startswith('"') and edge_type_raw.endswith('"'):
2800+
edge_type = edge_type_raw[1:-1]
2801+
else:
2802+
edge_type = str(edge_type_raw)
27712803

27722804
edges.append({"from": from_id, "to": to_id, "type": edge_type})
27732805
return edges

0 commit comments

Comments
 (0)