MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / Graph_BulkInsert

Function Graph_BulkInsert

src/commands/cmd_bulk_insert.c:51–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51int Graph_BulkInsert(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
52 if(argc < 3) return RedisModule_WrongArity(ctx);
53
54 // bulk-insert process a batch of node/edge creation generated by the
55 // bulk-insert utility
56
57 GraphContext *gc = NULL;
58 long long node_count = 0; // number of declared nodes
59 long long edge_count = 0; // number of declared edges
60
61 // get graph name
62 argv += 1; // skip "GRAPH.BULK"
63 RedisModuleString *rs_graph_name = *argv++;
64 const char *graphname = RedisModule_StringPtrLen(rs_graph_name, NULL);
65 argc -= 2; // skip "GRAPH.BULK [GRAPHNAME]"
66
67 bool begin = false;
68 if(_Graph_Bulk_Begin(ctx, &argv, &argc, rs_graph_name, graphname, &begin)
69 != BULK_OK) goto cleanup;
70
71 gc = GraphContext_Retrieve(ctx, rs_graph_name, false, begin);
72
73 // failed to retrieve GraphContext; an error has been emitted
74 if(gc == NULL) goto cleanup;
75
76 // read the user-provided counts for nodes and edges in the current query
77 if(RedisModule_StringToLongLong(*argv++, &node_count) != REDISMODULE_OK) {
78 RedisModule_ReplyWithError(ctx, "Error parsing node count.");
79 goto cleanup;
80 }
81
82 if(RedisModule_StringToLongLong(*argv++, &edge_count) != REDISMODULE_OK) {
83 RedisModule_ReplyWithError(ctx, "Error parsing relation count.");
84 goto cleanup;
85 }
86
87 argc -= 2; // already read node count and edge count
88
89 int rc = BulkInsert(ctx, gc, argv, argc, node_count, edge_count);
90
91 if(rc == BULK_FAIL) {
92 // if insertion failed, clean up keyspace and free added entities
93 GraphContext_DecreaseRefCount(gc);
94 RedisModuleKey *key = NULL;
95
96 key = RedisModule_OpenKey(ctx, rs_graph_name, REDISMODULE_WRITE);
97 RedisModule_DeleteKey(key);
98 RedisModule_CloseKey(key);
99
100 gc = NULL;
101 goto cleanup;
102 }
103
104 // successful bulk commands should always modify slaves
105 RedisModule_ReplicateVerbatim(ctx);
106
107 // replay to caller
108 char reply[1024];

Callers

nothing calls this directly

Calls 4

_Graph_Bulk_BeginFunction · 0.85
GraphContext_RetrieveFunction · 0.85
BulkInsertFunction · 0.85

Tested by

no test coverage detected