Skip to content

Commit e21f5bb

Browse files
lijicodefridayL
andauthored
fix porlar (#406)
* feat: fix sources * feat: fix sources * feat: fix nebular * feat: fix polardb edges * feat: format polardb --------- Co-authored-by: chunyu li <[email protected]>
1 parent 1f6757d commit e21f5bb

File tree

2 files changed

+80
-14
lines changed

2 files changed

+80
-14
lines changed

src/memos/graph_dbs/nebular.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ def _ensure_database_exists(self):
15511551
"""
15521552
self.execute_query(create_tag, auto_set_db=False)
15531553
else:
1554-
describe_query = f"DESCRIBE NODE TYPE Memory OF {graph_type_name};"
1554+
describe_query = f"DESCRIBE NODE TYPE Memory OF {graph_type_name}"
15551555
desc_result = self.execute_query(describe_query, auto_set_db=False)
15561556

15571557
memory_fields = []

src/memos/graph_dbs/polardb.py

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,24 +1776,61 @@ 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 = (
1782+
source_agtype.value
1783+
if hasattr(source_agtype, "value")
1784+
else str(source_agtype)
1785+
)
1786+
if (
1787+
isinstance(source_raw, str)
1788+
and source_raw.startswith('"')
1789+
and source_raw.endswith('"')
1790+
):
1791+
source = source_raw[1:-1]
1792+
else:
1793+
source = str(source_raw)
1794+
1795+
# Extract and clean target
1796+
target_raw = (
1797+
target_agtype.value
1798+
if hasattr(target_agtype, "value")
1799+
else str(target_agtype)
1800+
)
1801+
if (
1802+
isinstance(target_raw, str)
1803+
and target_raw.startswith('"')
1804+
and target_raw.endswith('"')
1805+
):
1806+
target = target_raw[1:-1]
1807+
else:
1808+
target = str(target_raw)
1809+
1810+
# Extract and clean edge type
1811+
type_raw = (
1812+
edge_agtype.value if hasattr(edge_agtype, "value") else str(edge_agtype)
1813+
)
1814+
if (
1815+
isinstance(type_raw, str)
1816+
and type_raw.startswith('"')
1817+
and type_raw.endswith('"')
1818+
):
1819+
edge_type = type_raw[1:-1]
1820+
else:
1821+
edge_type = str(type_raw)
1822+
17791823
edges.append(
17801824
{
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),
1825+
"source": source,
1826+
"target": target,
1827+
"type": edge_type,
17901828
}
17911829
)
17921830

17931831
except Exception as e:
17941832
logger.error(f"[EXPORT GRAPH - EDGES] Exception: {e}", exc_info=True)
17951833
raise RuntimeError(f"[EXPORT GRAPH - EDGES] Exception: {e}") from e
1796-
17971834
return {"nodes": nodes, "edges": edges}
17981835

17991836
@timed
@@ -2765,9 +2802,38 @@ def get_edges(
27652802

27662803
edges = []
27672804
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]
2805+
# Extract and clean from_id
2806+
from_id_raw = row[0].value if hasattr(row[0], "value") else row[0]
2807+
if (
2808+
isinstance(from_id_raw, str)
2809+
and from_id_raw.startswith('"')
2810+
and from_id_raw.endswith('"')
2811+
):
2812+
from_id = from_id_raw[1:-1]
2813+
else:
2814+
from_id = str(from_id_raw)
2815+
2816+
# Extract and clean to_id
2817+
to_id_raw = row[1].value if hasattr(row[1], "value") else row[1]
2818+
if (
2819+
isinstance(to_id_raw, str)
2820+
and to_id_raw.startswith('"')
2821+
and to_id_raw.endswith('"')
2822+
):
2823+
to_id = to_id_raw[1:-1]
2824+
else:
2825+
to_id = str(to_id_raw)
2826+
2827+
# Extract and clean edge_type
2828+
edge_type_raw = row[2].value if hasattr(row[2], "value") else row[2]
2829+
if (
2830+
isinstance(edge_type_raw, str)
2831+
and edge_type_raw.startswith('"')
2832+
and edge_type_raw.endswith('"')
2833+
):
2834+
edge_type = edge_type_raw[1:-1]
2835+
else:
2836+
edge_type = str(edge_type_raw)
27712837

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

0 commit comments

Comments
 (0)