use of com.baidu.hugegraph.entity.load.VertexMapping in project incubator-hugegraph-toolchain by apache.
the class LoadTaskService method buildVertexMappings.
private List<com.baidu.hugegraph.loader.mapping.VertexMapping> buildVertexMappings(GraphConnection connection, FileMapping fileMapping) {
int connId = connection.getId();
List<com.baidu.hugegraph.loader.mapping.VertexMapping> vMappings = new ArrayList<>();
for (VertexMapping mapping : fileMapping.getVertexMappings()) {
VertexLabelEntity vl = this.vlService.get(mapping.getLabel(), connId);
List<String> idFields = mapping.getIdFields();
Map<String, String> fieldMappings = mapping.fieldMappingToMap();
com.baidu.hugegraph.loader.mapping.VertexMapping vMapping;
if (vl.getIdStrategy().isCustomize()) {
Ex.check(idFields.size() == 1, "When the ID strategy is CUSTOMIZED, you must " + "select a column in the file as the id");
vMapping = new com.baidu.hugegraph.loader.mapping.VertexMapping(idFields.get(0), true);
} else {
assert vl.getIdStrategy().isPrimaryKey();
List<String> primaryKeys = vl.getPrimaryKeys();
Ex.check(idFields.size() >= 1 && idFields.size() == primaryKeys.size(), "When the ID strategy is PRIMARY_KEY, you must " + "select at least one column in the file as the " + "primary keys");
/*
* The id column can be unfold into multi sub-ids only
* when primarykeys contains just one field
*/
boolean unfold = idFields.size() == 1;
vMapping = new com.baidu.hugegraph.loader.mapping.VertexMapping(null, unfold);
for (int i = 0; i < primaryKeys.size(); i++) {
fieldMappings.put(idFields.get(i), primaryKeys.get(i));
}
}
// set label
vMapping.label(mapping.getLabel());
// set field_mapping
vMapping.mappingFields(fieldMappings);
// set value_mapping
vMapping.mappingValues(mapping.valueMappingToMap());
// set selected
vMapping.selectedFields().addAll(idFields);
vMapping.selectedFields().addAll(fieldMappings.keySet());
// set null_values
Set<Object> nullValues = new HashSet<>();
nullValues.addAll(mapping.getNullValues().getChecked());
nullValues.addAll(mapping.getNullValues().getCustomized());
vMapping.nullValues(nullValues);
// TODO: Update strategies
vMappings.add(vMapping);
}
return vMappings;
}
use of com.baidu.hugegraph.entity.load.VertexMapping in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method deleteVertexMapping.
@DeleteMapping("{id}/vertex-mappings/{vmid}")
public FileMapping deleteVertexMapping(@PathVariable("id") int id, @PathVariable("vmid") String vmid) {
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
VertexMapping vertexMapping = mapping.getVertexMapping(vmid);
boolean removed = mapping.getVertexMappings().remove(vertexMapping);
if (!removed) {
throw new ExternalException("load.file-mapping.vertex-mapping.not-exist.id", vmid);
}
this.service.update(mapping);
return mapping;
}
use of com.baidu.hugegraph.entity.load.VertexMapping in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method updateVertexMapping.
@PutMapping("{id}/vertex-mappings/{vmid}")
public FileMapping updateVertexMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @PathVariable("vmid") String vmId, @RequestBody VertexMapping newEntity) {
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
this.checkVertexMappingValid(connId, newEntity, mapping);
VertexMapping vertexMapping = mapping.getVertexMapping(vmId);
Ex.check(vertexMapping != null, "load.file-mapping.vertex-mapping.not-exist.id", vmId);
newEntity.setId(vmId);
Set<VertexMapping> vertexMappings = mapping.getVertexMappings();
vertexMappings.remove(vertexMapping);
vertexMappings.add(newEntity);
this.service.update(mapping);
return mapping;
}
Aggregations