Search in sources :

Example 1 with EdgeLabelEntity

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;
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) ArrayList(java.util.ArrayList) EdgeMapping(com.baidu.hugegraph.entity.load.EdgeMapping) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) HashSet(java.util.HashSet)

Example 2 with EdgeLabelEntity

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;
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ArrayList(java.util.ArrayList)

Example 3 with EdgeLabelEntity

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;
}
Also used : ConflictDetail(com.baidu.hugegraph.entity.schema.ConflictDetail) EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) HashMap(java.util.HashMap)

Example 4 with EdgeLabelEntity

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");
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity)

Example 5 with EdgeLabelEntity

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);
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) FileSetting(com.baidu.hugegraph.entity.load.FileSetting) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Aggregations

EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)8 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)5 ArrayList (java.util.ArrayList)3 HugeClient (com.baidu.hugegraph.driver.HugeClient)2 HashSet (java.util.HashSet)2 GraphManager (com.baidu.hugegraph.driver.GraphManager)1 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)1 FileSetting (com.baidu.hugegraph.entity.load.FileSetting)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)1 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1