| 195 | } |
| 196 | |
| 197 | static int _BulkInsert_ProcessNodeFile |
| 198 | ( |
| 199 | GraphContext* gc, |
| 200 | const char* data, |
| 201 | size_t data_len |
| 202 | ) { |
| 203 | uint prop_count; |
| 204 | size_t data_idx = 0; |
| 205 | |
| 206 | // read the CSV file header labels and update all schemas |
| 207 | int* label_ids = _BulkInsert_ReadHeaderLabels(gc, SCHEMA_NODE, data, &data_idx); |
| 208 | uint label_count = array_len(label_ids); |
| 209 | // read the CSV header properties and collect their indices |
| 210 | Attribute_ID* prop_indices = _BulkInsert_ReadHeaderProperties(gc, SCHEMA_NODE, data, |
| 211 | &data_idx, &prop_count); |
| 212 | |
| 213 | // sync each matrix once |
| 214 | ASSERT(Graph_GetMatrixPolicy(gc->g) == SYNC_POLICY_RESIZE); |
| 215 | |
| 216 | for (uint i = 0; i < label_count; i++) { |
| 217 | Graph_GetLabelMatrix(gc->g, label_ids[i]); |
| 218 | } |
| 219 | |
| 220 | // sync node-label matrix |
| 221 | Graph_GetNodeLabelMatrix(gc->g); |
| 222 | Graph_SetMatrixPolicy(gc->g, SYNC_POLICY_NOP); |
| 223 | |
| 224 | //-------------------------------------------------------------------------- |
| 225 | // load nodes |
| 226 | //-------------------------------------------------------------------------- |
| 227 | |
| 228 | while (data_idx < data_len) { |
| 229 | Node n = GE_NEW_NODE(); |
| 230 | GraphEntity* ge; |
| 231 | Graph_CreateNode(gc->g, &n, label_ids, label_count); |
| 232 | ge = (GraphEntity*)&n; |
| 233 | // process entity attributes |
| 234 | for (uint i = 0; i < prop_count; i++) { |
| 235 | SIValue value = _BulkInsert_ReadProperty(data, &data_idx); |
| 236 | // skip invalid attribute values |
| 237 | if (!(SI_TYPE(value) & SI_VALID_PROPERTY_VALUE)) |
| 238 | continue; |
| 239 | GraphEntity_AddProperty(ge, prop_indices[i], value); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | Graph_SetMatrixPolicy(gc->g, SYNC_POLICY_RESIZE); |
| 244 | if (prop_indices) rm_free(prop_indices); |
| 245 | array_free(label_ids); |
| 246 | |
| 247 | return BULK_OK; |
| 248 | } |
| 249 | |
| 250 | static int _BulkInsert_ProcessEdgeFile |
| 251 | ( |
no test coverage detected