@@ -170,7 +170,7 @@ def getEdgeLabelListAfterPreprocessing(G: nx.DiGraph):
170170
171171
172172def addAllNodesIntoAGE (connection : psycopg .connect , graphName : str , G : nx .DiGraph , node_label_list : Set ):
173- """Add all node to AGE"""
173+ """Add all node to AGE using the unified vertex table """
174174 try :
175175 queue_data = {label : [] for label in node_label_list }
176176 id_data = {}
@@ -179,9 +179,11 @@ def addAllNodesIntoAGE(connection: psycopg.connect, graphName: str, G: nx.DiGrap
179179 json_string = json .dumps (data ['properties' ])
180180 queue_data [data ['label' ]].append ((json_string ,))
181181
182+ unified_table = f"{ graphName } ._ag_label_vertex"
182183 for label , rows in queue_data .items ():
183- table_name = """%s."%s" """ % (graphName , label )
184- insert_query = f"INSERT INTO { table_name } (properties) VALUES (%s) RETURNING id"
184+ # Get the label table OID for the labels column
185+ label_table = f'{ graphName } ."{ label } "'
186+ insert_query = f"INSERT INTO { unified_table } (properties, labels) VALUES (%s, '{ label_table } '::regclass::oid) RETURNING id"
185187 cursor = connection .cursor ()
186188 cursor .executemany (insert_query , rows , returning = True )
187189 ids = []
@@ -224,19 +226,21 @@ def addAllEdgesIntoAGE(connection: psycopg.connect, graphName: str, G: nx.DiGrap
224226
225227
226228def addAllNodesIntoNetworkx (connection : psycopg .connect , graphName : str , G : nx .DiGraph ):
227- """Add all nodes to Networkx"""
228- node_label_list = get_vlabel (connection , graphName )
229+ """Add all nodes to Networkx from the unified vertex table"""
229230 try :
230- for label in node_label_list :
231- with connection .cursor () as cursor :
232- cursor .execute ("""
233- SELECT id, CAST(properties AS VARCHAR)
234- FROM %s."%s";
235- """ % (graphName , label ))
236- rows = cursor .fetchall ()
237- for row in rows :
238- G .add_node (int (row [0 ]), label = label ,
239- properties = json .loads (row [1 ]))
231+ with connection .cursor () as cursor :
232+ # Read all vertices from unified table, getting label from labels column
233+ cursor .execute ("""
234+ SELECT id, CAST(properties AS VARCHAR),
235+ ag_catalog._label_name_from_table_oid(labels) as label
236+ FROM %s._ag_label_vertex;
237+ """ % graphName )
238+ rows = cursor .fetchall ()
239+ for row in rows :
240+ # Empty string label means default/unlabeled vertex
241+ label = row [2 ] if row [2 ] else '_ag_label_vertex'
242+ G .add_node (int (row [0 ]), label = label ,
243+ properties = json .loads (row [1 ]))
240244 except Exception as e :
241245 print (e )
242246
0 commit comments