use of com.baidu.hugegraph.entity.schema.EdgeLabelEntity 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.EdgeLabelEntity in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method list.
public List<EdgeLabelEntity> list(Collection<String> names, int connId, boolean emptyAsAll) {
HugeClient client = this.client(connId);
List<EdgeLabel> edgeLabels;
if (CollectionUtils.isEmpty(names)) {
if (emptyAsAll) {
edgeLabels = client.schema().getEdgeLabels();
} else {
edgeLabels = new ArrayList<>();
}
} else {
edgeLabels = client.schema().getEdgeLabels(new ArrayList<>(names));
}
List<IndexLabel> indexLabels = client.schema().getIndexLabels();
List<EdgeLabelEntity> results = new ArrayList<>(edgeLabels.size());
edgeLabels.forEach(edgeLabel -> {
results.add(convert(edgeLabel, indexLabels));
});
return results;
}
use of com.baidu.hugegraph.entity.schema.EdgeLabelEntity in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method checkConflict.
public ConflictDetail checkConflict(ConflictCheckEntity entity, int connId, boolean compareEachOther) {
ConflictDetail detail = new ConflictDetail(SchemaType.EDGE_LABEL);
if (CollectionUtils.isEmpty(entity.getElEntities())) {
return detail;
}
Map<String, EdgeLabelEntity> originElEntities = new HashMap<>();
for (EdgeLabelEntity e : this.list(connId)) {
originElEntities.put(e.getName(), e);
}
this.pkService.checkConflict(entity.getPkEntities(), detail, connId, compareEachOther);
this.piService.checkConflict(entity.getPiEntities(), detail, connId, compareEachOther);
this.vlService.checkConflict(entity.getVlEntities(), detail, connId, compareEachOther);
for (EdgeLabelEntity elEntity : entity.getElEntities()) {
// Firstly check if any properties are conflicted
if (detail.anyPropertyKeyConflict(elEntity.getPropNames())) {
detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
continue;
}
// Then check if any property indexes are conflicted
if (detail.anyPropertyIndexConflict(elEntity.getIndexProps())) {
detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
continue;
}
// Then determine if source/target vertex labels are conflicted
if (detail.anyVertexLabelConflict(elEntity.getLinkLabels())) {
detail.add(elEntity, ConflictStatus.DEP_CONFLICT);
continue;
}
// Then check conflict of edge label itself
EdgeLabelEntity originElEntity = originElEntities.get(elEntity.getName());
ConflictStatus status = SchemaEntity.compare(elEntity, originElEntity);
detail.add(elEntity, status);
}
if (compareEachOther) {
compareWithEachOther(detail, SchemaType.EDGE_LABEL);
}
return detail;
}
use of com.baidu.hugegraph.entity.schema.EdgeLabelEntity in project incubator-hugegraph-toolchain by apache.
the class GraphController method checkParamsValid.
private void checkParamsValid(int connId, EdgeEntity entity, boolean create) {
Ex.check(!StringUtils.isEmpty(entity.getLabel()), "common.param.cannot-be-null-or-empty", "label");
// If schema doesn't exist, it will throw exception
EdgeLabelEntity elEntity = this.elService.get(entity.getLabel(), connId);
if (create) {
Ex.check(entity.getId() == null, "common.param.must-be-null", "id");
} else {
Ex.check(entity.getId() != null, "common.param.cannot-be-null", "id");
}
Ex.check(entity.getSourceId() != null, "common.param.must-be-null", "source_id");
Ex.check(entity.getTargetId() != null, "common.param.must-be-null", "target_id");
Set<String> nonNullableProps = elEntity.getNonNullableProps();
Map<String, Object> properties = entity.getProperties();
Ex.check(properties.keySet().containsAll(nonNullableProps), "graph.edge.all-nonnullable-prop.should-be-setted");
}
use of com.baidu.hugegraph.entity.schema.EdgeLabelEntity 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