@@ -101,7 +101,7 @@ static bool insert_edge(GRAPH_global_context *ggctx, graphid edge_id,
101
101
graphid end_vertex_id , Oid edge_label_table_oid );
102
102
static bool insert_vertex_edge (GRAPH_global_context * ggctx ,
103
103
graphid start_vertex_id , graphid end_vertex_id ,
104
- graphid edge_id );
104
+ graphid edge_id , char * edge_label_name );
105
105
static bool insert_vertex_entry (GRAPH_global_context * ggctx , graphid vertex_id ,
106
106
Oid vertex_label_table_oid ,
107
107
Datum vertex_properties );
@@ -330,10 +330,11 @@ static bool insert_vertex_entry(GRAPH_global_context *ggctx, graphid vertex_id,
330
330
*/
331
331
static bool insert_vertex_edge (GRAPH_global_context * ggctx ,
332
332
graphid start_vertex_id , graphid end_vertex_id ,
333
- graphid edge_id )
333
+ graphid edge_id , char * edge_label_name )
334
334
{
335
335
vertex_entry * value = NULL ;
336
- bool found = false;
336
+ bool start_found = false;
337
+ bool end_found = false;
337
338
bool is_selfloop = false;
338
339
339
340
/* is it a self loop */
@@ -342,39 +343,70 @@ static bool insert_vertex_edge(GRAPH_global_context *ggctx,
342
343
/* search for the start vertex of the edge */
343
344
value = (vertex_entry * )hash_search (ggctx -> vertex_hashtable ,
344
345
(void * )& start_vertex_id , HASH_FIND ,
345
- & found );
346
- /* vertices were preloaded so it must be there */
347
- Assert (found );
348
- if (!found )
349
- {
350
- return found ;
351
- }
346
+ & start_found );
352
347
353
- /* if it is a self loop, add the edge to edges_self and we're done */
354
- if (is_selfloop )
348
+ /*
349
+ * If we found the start_vertex_id and it is a self loop, add the edge to
350
+ * edges_self and we're done
351
+ */
352
+ if (start_found && is_selfloop )
355
353
{
356
354
value -> edges_self = append_graphid (value -> edges_self , edge_id );
357
- return found ;
355
+ return true;
356
+ }
357
+ /*
358
+ * Otherwise, if we found the start_vertex_id add the edge to the edges_out
359
+ * list of the start vertex
360
+ */
361
+ else if (start_found )
362
+ {
363
+ value -> edges_out = append_graphid (value -> edges_out , edge_id );
358
364
}
359
-
360
- /* add the edge to the edges_out list of the start vertex */
361
- value -> edges_out = append_graphid (value -> edges_out , edge_id );
362
365
363
366
/* search for the end vertex of the edge */
364
367
value = (vertex_entry * )hash_search (ggctx -> vertex_hashtable ,
365
368
(void * )& end_vertex_id , HASH_FIND ,
366
- & found );
367
- /* vertices were preloaded so it must be there */
368
- Assert (found );
369
- if (!found )
369
+ & end_found );
370
+
371
+ /*
372
+ * If we found the start_vertex_id and the end_vertex_id add the edge to the
373
+ * edges_in list of the end vertex
374
+ */
375
+ if (start_found && end_found )
370
376
{
371
- return found ;
377
+ value -> edges_in = append_graphid (value -> edges_in , edge_id );
378
+ return true;
379
+ }
380
+ /*
381
+ * Otherwise we need to generate the appropriate warning message about the
382
+ * dangling edge that we found.
383
+ */
384
+ else if (!start_found && end_found )
385
+ {
386
+ ereport (WARNING ,
387
+ (errcode (ERRCODE_DATA_EXCEPTION ),
388
+ errmsg ("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s" ,
389
+ edge_id , start_vertex_id , end_vertex_id ,
390
+ edge_label_name , "start vertex not found" )));
391
+ }
392
+ else if (start_found && !end_found )
393
+ {
394
+ ereport (WARNING ,
395
+ (errcode (ERRCODE_DATA_EXCEPTION ),
396
+ errmsg ("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s" ,
397
+ edge_id , start_vertex_id , end_vertex_id ,
398
+ edge_label_name , "end vertex not found" )));
399
+ }
400
+ else
401
+ {
402
+ ereport (WARNING ,
403
+ (errcode (ERRCODE_DATA_EXCEPTION ),
404
+ errmsg ("edge: [id: %ld, start: %ld, end: %ld, label: %s] %s" ,
405
+ edge_id , start_vertex_id , end_vertex_id ,
406
+ edge_label_name , "start and end vertices not found" )));
372
407
}
373
408
374
- /* add the edge to the edges_in list of the end vertex */
375
- value -> edges_in = append_graphid (value -> edges_in , edge_id );
376
-
377
- return found ;
409
+ return false;
378
410
}
379
411
380
412
/* helper routine to load all vertices into the GRAPH global vertex hashtable */
@@ -430,7 +462,12 @@ static void load_vertex_hashtable(GRAPH_global_context *ggctx)
430
462
bool inserted = false;
431
463
432
464
/* something is wrong if this isn't true */
465
+ if (!HeapTupleIsValid (tuple ))
466
+ {
467
+ elog (ERROR , "load_vertex_hashtable: !HeapTupleIsValid" );
468
+ }
433
469
Assert (HeapTupleIsValid (tuple ));
470
+
434
471
/* get the vertex id */
435
472
vertex_id = DatumGetInt64 (column_get_datum (tupdesc , tuple , 0 , "id" ,
436
473
GRAPHIDOID , true));
@@ -533,7 +570,12 @@ static void load_edge_hashtable(GRAPH_global_context *ggctx)
533
570
bool inserted = false;
534
571
535
572
/* something is wrong if this isn't true */
573
+ if (!HeapTupleIsValid (tuple ))
574
+ {
575
+ elog (ERROR , "load_edge_hashtable: !HeapTupleIsValid" );
576
+ }
536
577
Assert (HeapTupleIsValid (tuple ));
578
+
537
579
/* get the edge id */
538
580
edge_id = DatumGetInt64 (column_get_datum (tupdesc , tuple , 0 , "id" ,
539
581
GRAPHIDOID , true));
@@ -568,11 +610,13 @@ static void load_edge_hashtable(GRAPH_global_context *ggctx)
568
610
569
611
/* insert the edge into the start and end vertices edge lists */
570
612
inserted = insert_vertex_edge (ggctx , edge_vertex_start_id ,
571
- edge_vertex_end_id , edge_id );
572
- /* this insert must not fail */
613
+ edge_vertex_end_id , edge_id ,
614
+ edge_label_name );
573
615
if (!inserted )
574
616
{
575
- elog (ERROR , "insert_vertex_edge: failed to insert" );
617
+ ereport (WARNING ,
618
+ (errcode (ERRCODE_DATA_EXCEPTION ),
619
+ errmsg ("ignored malformed or dangling edge" )));
576
620
}
577
621
}
578
622
0 commit comments