use of com.baidu.hugegraph.entity.schema.VertexLabelEntity 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.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.
the class LoadTaskService method buildEdgeMappings.
private List<com.baidu.hugegraph.loader.mapping.EdgeMapping> buildEdgeMappings(GraphConnection connection, FileMapping fileMapping) {
int connId = connection.getId();
List<com.baidu.hugegraph.loader.mapping.EdgeMapping> eMappings = new ArrayList<>();
for (EdgeMapping mapping : fileMapping.getEdgeMappings()) {
List<String> sourceFields = mapping.getSourceFields();
List<String> targetFields = mapping.getTargetFields();
EdgeLabelEntity el = this.elService.get(mapping.getLabel(), connId);
VertexLabelEntity svl = this.vlService.get(el.getSourceLabel(), connId);
VertexLabelEntity tvl = this.vlService.get(el.getTargetLabel(), connId);
Map<String, String> fieldMappings = mapping.fieldMappingToMap();
/*
* When id strategy is customize or primaryKeys contains
* just one field, the param 'unfold' can be true
*/
boolean unfoldSource = true;
if (svl.getIdStrategy().isPrimaryKey()) {
List<String> primaryKeys = svl.getPrimaryKeys();
Ex.check(sourceFields.size() >= 1 && sourceFields.size() == primaryKeys.size(), "When the source vertex ID strategy is CUSTOMIZED, " + "you must select at least one column in the file " + "as the id");
for (int i = 0; i < primaryKeys.size(); i++) {
fieldMappings.put(sourceFields.get(i), primaryKeys.get(i));
}
if (sourceFields.size() > 1) {
unfoldSource = false;
}
}
boolean unfoldTarget = true;
if (tvl.getIdStrategy().isPrimaryKey()) {
List<String> primaryKeys = tvl.getPrimaryKeys();
Ex.check(targetFields.size() >= 1 && targetFields.size() == primaryKeys.size(), "When the target vertex ID strategy is CUSTOMIZED, " + "you must select at least one column in the file " + "as the id");
for (int i = 0; i < primaryKeys.size(); i++) {
fieldMappings.put(targetFields.get(i), primaryKeys.get(i));
}
if (targetFields.size() > 1) {
unfoldTarget = false;
}
}
com.baidu.hugegraph.loader.mapping.EdgeMapping eMapping;
eMapping = new com.baidu.hugegraph.loader.mapping.EdgeMapping(sourceFields, unfoldSource, targetFields, unfoldTarget);
// set label
eMapping.label(mapping.getLabel());
// set field_mapping
eMapping.mappingFields(fieldMappings);
// set value_mapping
eMapping.mappingValues(mapping.valueMappingToMap());
// set selected
eMapping.selectedFields().addAll(sourceFields);
eMapping.selectedFields().addAll(targetFields);
eMapping.selectedFields().addAll(fieldMappings.keySet());
// set null_values
Set<Object> nullValues = new HashSet<>();
nullValues.addAll(mapping.getNullValues().getChecked());
nullValues.addAll(mapping.getNullValues().getCustomized());
eMapping.nullValues(nullValues);
eMappings.add(eMapping);
}
return eMappings;
}
use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.
the class VertexLabelService method checkConflict.
public void checkConflict(List<VertexLabelEntity> entities, ConflictDetail detail, int connId, boolean compareEachOther) {
if (CollectionUtils.isEmpty(entities)) {
return;
}
Map<String, VertexLabelEntity> originEntities = new HashMap<>();
for (VertexLabelEntity entity : this.list(connId)) {
originEntities.put(entity.getName(), entity);
}
for (VertexLabelEntity entity : entities) {
if (detail.anyPropertyKeyConflict(entity.getPropNames())) {
detail.add(entity, ConflictStatus.DEP_CONFLICT);
continue;
}
if (detail.anyPropertyIndexConflict(entity.getIndexProps())) {
detail.add(entity, ConflictStatus.DEP_CONFLICT);
continue;
}
VertexLabelEntity originEntity = originEntities.get(entity.getName());
ConflictStatus status = SchemaEntity.compare(entity, originEntity);
detail.add(entity, status);
}
// Compare resued entities with each other
if (compareEachOther) {
compareWithEachOther(detail, SchemaType.VERTEX_LABEL);
}
}
use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.
the class VertexLabelService method list.
public List<VertexLabelEntity> list(Collection<String> names, int connId, boolean emptyAsAll) {
HugeClient client = this.client(connId);
List<VertexLabel> vertexLabels;
if (CollectionUtils.isEmpty(names)) {
if (emptyAsAll) {
vertexLabels = client.schema().getVertexLabels();
} else {
vertexLabels = new ArrayList<>();
}
} else {
vertexLabels = client.schema().getVertexLabels(new ArrayList<>(names));
}
List<IndexLabel> indexLabels = client.schema().getIndexLabels();
List<VertexLabelEntity> results = new ArrayList<>(vertexLabels.size());
vertexLabels.forEach(vertexLabel -> {
results.add(join(vertexLabel, indexLabels));
});
return results;
}
use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method checkEdgeMappingValid.
private void checkEdgeMappingValid(int connId, EdgeMapping edgeMapping, FileMapping fileMapping) {
EdgeLabelEntity el = this.elService.get(edgeMapping.getLabel(), connId);
VertexLabelEntity source = this.vlService.get(el.getSourceLabel(), connId);
VertexLabelEntity target = this.vlService.get(el.getTargetLabel(), connId);
Ex.check(!source.getIdStrategy().isAutomatic(), "load.file-mapping.vertex.automatic-id-unsupported");
Ex.check(!target.getIdStrategy().isAutomatic(), "load.file-mapping.vertex.automatic-id-unsupported");
Ex.check(!CollectionUtils.isEmpty(edgeMapping.getSourceFields()), "load.file-mapping.edge.source-fields-cannot-be-empty");
Ex.check(!CollectionUtils.isEmpty(edgeMapping.getTargetFields()), "load.file-mapping.edge.target-fields-cannot-be-empty");
FileSetting fileSetting = fileMapping.getFileSetting();
List<String> columnNames = fileSetting.getColumnNames();
Ex.check(columnNames.containsAll(edgeMapping.getSourceFields()), "load.file-mapping.edge.source-fields-should-in-column-names", edgeMapping.getSourceFields(), columnNames);
Ex.check(columnNames.containsAll(edgeMapping.getTargetFields()), "load.file-mapping.edge.target-fields-should-in-column-names", edgeMapping.getTargetFields(), columnNames);
Ex.check(CollectionUtil.allUnique(edgeMapping.fieldMappingToMap().values()), "load.file-mapping.mapping-fields-should-no-duplicate");
this.checkMappingValid(edgeMapping, fileMapping);
}
Aggregations