read the label strings from a header, update schemas, and retrieve the label IDs
| 30 | |
| 31 | // read the label strings from a header, update schemas, and retrieve the label IDs |
| 32 | static int* _BulkInsert_ReadHeaderLabels |
| 33 | ( |
| 34 | GraphContext* gc, |
| 35 | SchemaType t, |
| 36 | const char* data, |
| 37 | size_t* data_idx |
| 38 | ) { |
| 39 | ASSERT(gc != NULL); |
| 40 | ASSERT(data != NULL); |
| 41 | ASSERT(data_idx != NULL); |
| 42 | |
| 43 | // first sequence is entity label(s) |
| 44 | const char* labels = data + *data_idx; |
| 45 | int labels_len = strlen(labels); |
| 46 | *data_idx += labels_len + 1; |
| 47 | |
| 48 | // array of all label IDs |
| 49 | int* label_ids = array_new(int, 1); |
| 50 | // stack variable to contain a single label |
| 51 | char label[labels_len + 1]; |
| 52 | |
| 53 | while (true) { |
| 54 | // look for a colon delimiting another label |
| 55 | char* found = strchr(labels, ':'); |
| 56 | if (found) { |
| 57 | ASSERT(t == SCHEMA_NODE); // only nodes can have multiple labels |
| 58 | // this entity file describes multiple labels, copy the current one |
| 59 | size_t len = found - labels; |
| 60 | memcpy(label, labels, len); |
| 61 | label[len] = '\0'; |
| 62 | // update the labels pointer for the next seek |
| 63 | labels += len + 1; |
| 64 | } else { |
| 65 | // reached the last (or only) label; copy it |
| 66 | size_t len = strlen(labels); |
| 67 | // Also copy the terminating NULL character. |
| 68 | memcpy(label, labels, len + 1); |
| 69 | } |
| 70 | |
| 71 | // try to retrieve the label's schema |
| 72 | Schema* s = GraphContext_GetSchema(gc, label, t); |
| 73 | // create the schema if it does not already exist |
| 74 | if (s == NULL) { |
| 75 | s = GraphContext_AddSchema(gc, label, t); |
| 76 | } |
| 77 | |
| 78 | // store the label ID |
| 79 | array_append(label_ids, Schema_GetID(s)); |
| 80 | |
| 81 | // break if we've exhausted all labels |
| 82 | if (!found) break; |
| 83 | } |
| 84 | |
| 85 | return label_ids; |
| 86 | } |
| 87 | |
| 88 | // read the property keys from a header |
| 89 | static Attribute_ID* _BulkInsert_ReadHeaderProperties |
no test coverage detected