| 248 | } |
| 249 | |
| 250 | static int _BulkInsert_ProcessEdgeFile |
| 251 | ( |
| 252 | GraphContext* gc, |
| 253 | const char* data, |
| 254 | size_t data_len |
| 255 | ) { |
| 256 | int relation_id; |
| 257 | uint prop_count; |
| 258 | size_t data_idx = 0; |
| 259 | |
| 260 | // read the CSV file header |
| 261 | // and commit all labels and properties it introduces |
| 262 | int* type_ids = _BulkInsert_ReadHeaderLabels(gc, SCHEMA_EDGE, data, &data_idx); |
| 263 | uint type_count = array_len(type_ids); |
| 264 | |
| 265 | // edges can only have one type |
| 266 | ASSERT(type_count == 1); |
| 267 | |
| 268 | int type_id = type_ids[0]; |
| 269 | Attribute_ID* prop_indices = _BulkInsert_ReadHeaderProperties(gc, SCHEMA_EDGE, |
| 270 | data, &data_idx, &prop_count); |
| 271 | |
| 272 | // sync matrix once |
| 273 | ASSERT(Graph_GetMatrixPolicy(gc->g) == SYNC_POLICY_RESIZE); |
| 274 | Graph_GetRelationMatrix(gc->g, type_id, false); |
| 275 | Graph_GetAdjacencyMatrix(gc->g, false); |
| 276 | Graph_SetMatrixPolicy(gc->g, SYNC_POLICY_NOP); |
| 277 | |
| 278 | //-------------------------------------------------------------------------- |
| 279 | // load edges |
| 280 | //-------------------------------------------------------------------------- |
| 281 | |
| 282 | while (data_idx < data_len) { |
| 283 | Edge e; |
| 284 | GraphEntity* ge; |
| 285 | |
| 286 | // next 8 bytes are source ID |
| 287 | NodeID src = *(NodeID*)&data[data_idx]; |
| 288 | data_idx += sizeof(NodeID); |
| 289 | // next 8 bytes are destination ID |
| 290 | NodeID dest = *(NodeID*)&data[data_idx]; |
| 291 | data_idx += sizeof(NodeID); |
| 292 | |
| 293 | Graph_CreateEdge(gc->g, src, dest, type_id, &e); |
| 294 | ge = (GraphEntity*)&e; |
| 295 | |
| 296 | // process entity attributes |
| 297 | for (uint i = 0; i < prop_count; i++) { |
| 298 | SIValue value = _BulkInsert_ReadProperty(data, &data_idx); |
| 299 | // skip invalid attribute values |
| 300 | if (!(SI_TYPE(value) & SI_VALID_PROPERTY_VALUE)) { |
| 301 | continue; |
| 302 | } |
| 303 | |
| 304 | GraphEntity_AddProperty(ge, prop_indices[i], value); |
| 305 | } |
| 306 | } |
| 307 |
no test coverage detected