Fix mis-using directed edge in PostgreSQL AGE graph storage

This commit is contained in:
yangdx
2025-04-15 16:49:36 +08:00
parent 50e9f938a4
commit ce0aeaf9b4

View File

@@ -1262,7 +1262,7 @@ class PGGraphStorage(BaseGraphStorage):
tgt_label = target_node_id.strip('"') tgt_label = target_node_id.strip('"')
query = """SELECT * FROM cypher('%s', $$ query = """SELECT * FROM cypher('%s', $$
MATCH (a:base {entity_id: "%s"})-[r]->(b:base {entity_id: "%s"}) MATCH (a:base {entity_id: "%s"})-[r]-(b:base {entity_id: "%s"})
RETURN properties(r) as edge_properties RETURN properties(r) as edge_properties
LIMIT 1 LIMIT 1
$$) AS (edge_properties agtype)""" % ( $$) AS (edge_properties agtype)""" % (
@@ -1374,7 +1374,7 @@ class PGGraphStorage(BaseGraphStorage):
MATCH (source:base {entity_id: "%s"}) MATCH (source:base {entity_id: "%s"})
WITH source WITH source
MATCH (target:base {entity_id: "%s"}) MATCH (target:base {entity_id: "%s"})
MERGE (source)-[r:DIRECTED]->(target) MERGE (source)-[r:DIRECTED]-(target)
SET r += %s SET r += %s
RETURN r RETURN r
$$) AS (r agtype)""" % ( $$) AS (r agtype)""" % (
@@ -1447,7 +1447,7 @@ class PGGraphStorage(BaseGraphStorage):
tgt_label = target.strip('"') tgt_label = target.strip('"')
query = """SELECT * FROM cypher('%s', $$ query = """SELECT * FROM cypher('%s', $$
MATCH (a:base {entity_id: "%s"})-[r]->(b:base {entity_id: "%s"}) MATCH (a:base {entity_id: "%s"})-[r]-(b:base {entity_id: "%s"})
DELETE r DELETE r
$$) AS (r agtype)""" % (self.graph_name, src_label, tgt_label) $$) AS (r agtype)""" % (self.graph_name, src_label, tgt_label)
@@ -1723,7 +1723,7 @@ class PGGraphStorage(BaseGraphStorage):
if node_label == "*": if node_label == "*":
query = f"""SELECT * FROM cypher('{self.graph_name}', $$ query = f"""SELECT * FROM cypher('{self.graph_name}', $$
MATCH (n:base) MATCH (n:base)
OPTIONAL MATCH (n)-[r]->(target:base) OPTIONAL MATCH (n)-[r]-(target:base)
RETURN collect(distinct n) AS n, collect(distinct r) AS r RETURN collect(distinct n) AS n, collect(distinct r) AS r
LIMIT {max_nodes} LIMIT {max_nodes}
$$) AS (n agtype, r agtype)""" $$) AS (n agtype, r agtype)"""