Cosmos GraphBulkExecutorV3 Not Adding Edges C#

38 Views Asked by At

I'm using the GraphBulkExecutor try and import data into an Azure Cosmos Data (Gremlin). I can add vertex fine but edges are not being added and I'm not sure what I'm doing wrong.

(BaseSchedule) - has_schedule -> (Schedule).

A BaseSchedule defines a unique train id, start date, end date. Edges don't need a property in this case, and the partition key is "/_id". A 'Schedule' is just a vertex containing the day.

All the ideas are just an increment of a single property called 'schedId'. So the first node BaseSchedule is 1, Schedules is 2-60 and edge should be 61. I wasn't sure if vertexes and edges can have the same id, or even if nodes with different labels can share id's.

The BaseSchedule should link to all the child Schedules.

An example of a BaseSchedule:

{BaseSchedule: "A12345P230605", "TrainUID": "A12345", "StartDate": 25-06-2023, "EndDate":2023-08-01, "ATOC": "AA", BTOC: 20, "StartTiploc":"KNGX", EndTiploc:"EDINBUR", "PowerType": "D"}

 List<GremlinVertex> scheds = new List<GremlinVertex>(10000);
                    List<GremlinEdge> schedsEdge = new List<GremlinEdge>(10000);
                    foreach (var sch in data.Data.BaseSchedules)
                    {
                        sch.Id = schedId++;
                        GremlinVertex gv = new GremlinVertex($"{sch.Id}", "BaseSchedule");
                        gv.AddProperty("_id", sch.TrainUID);
                        gv.AddProperty("DatabaseId", sch.DatabaseId);
                        gv.AddProperty("TrainUID", sch.TrainUID);
                        gv.AddProperty("StartDate", sch.Schedule_Start_Date);
                        gv.AddProperty("EndDate", sch.Schedule_End_Date);
                        gv.AddProperty("StartTiploc", sch.StartTiploc);
                        gv.AddProperty("EndTiploc", sch.EndTiploc);
                        gv.AddProperty("ATOC", sch.ATOC);
                        gv.AddProperty("BTOC", sch.BTOC);
                        gv.AddProperty("PowerType", sch.PowerType);
                        scheds.Add(gv);

                        //Gets all days the schedule will run between start and end date
                        foreach (var iSch in sch.GetIndividualSchedules())
                        {
                            iSch.Id = schedId++;
                            GremlinVertex gv2 = new GremlinVertex($"{iSch.Id}", "Schedule");                               
                            gv2.AddProperty("_id", iSch.DatabaseId);
                            gv2.AddProperty("TrainUID", iSch.TrainUID);
                            gv2.AddProperty("Date", iSch.Date);
                            scheds.Add(gv2);

                            GremlinEdge ge = new GremlinEdge($"{schedId++}", "has_schedule", $"{sch.Id}", $"{iSch.Id}", 
                                "BaseSchedule", "Schedule", $"{sch.Id}", $"{iSch.Id}");
                            ge.AddProperty("DatabaseId", schedId);
                            ge.AddProperty("Date", iSch.Date);                                
                            schedsEdge.Add(ge);
                        }

                        if (scheds.Count >= 5000)
                        {
                            var resSched1 = cosmos.BulkImportAsync(scheds, true).Result;
                            var resSchedEdge1 = cosmos.BulkImportAsync(schedsEdge).Result;

                            if (resSched1.Failures.Count > 0 || resSchedEdge1.Failures.Count > 0)
                            {
                                ;
                            }

                            scheds.Clear();
                            schedsEdge.Clear();
                        }
                        break;
                    }
0

There are 0 best solutions below