Search in sources :

Example 11 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class SchemaService method collectIndexLabels.

public static List<IndexLabel> collectIndexLabels(SchemaLabelEntity entity, HugeClient client) {
    List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
    if (CollectionUtils.isEmpty(propertyIndexes)) {
        return Collections.emptyList();
    }
    boolean isVertex = entity.getSchemaType().isVertexLabel();
    String baseValue = entity.getName();
    SchemaManager schema = client.schema();
    List<IndexLabel> indexLabels = new ArrayList<>(propertyIndexes.size());
    for (PropertyIndex index : propertyIndexes) {
        String[] fields = toStringArray(index.getFields());
        IndexLabel indexLabel = schema.indexLabel(index.getName()).on(isVertex, baseValue).indexType(index.getType()).by(fields).build();
        indexLabels.add(indexLabel);
    }
    return indexLabels;
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 12 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method update.

public void update(VertexLabelUpdateEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    // All existed indexlabels
    List<IndexLabel> existedIndexLabels = client.schema().getIndexLabels();
    List<String> existedIndexLabelNames = collectNames(existedIndexLabels);
    List<String> addedIndexLabelNames = entity.getAppendPropertyIndexNames();
    List<IndexLabel> addedIndexLabels = convertIndexLabels(entity.getAppendPropertyIndexes(), client, true, entity.getName());
    List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
    if (addedIndexLabelNames != null) {
        for (String name : addedIndexLabelNames) {
            if (existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.append-index-existed", entity.getName(), name);
            }
        }
    }
    if (removedIndexLabelNames != null) {
        for (String name : removedIndexLabelNames) {
            if (!existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.remove-index-unexisted", entity.getName(), name);
            }
        }
    }
    try {
        // NOTE: property can append but doesn't support eliminate now
        client.schema().appendVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.update.failed", e, entity.getName());
    }
    this.piService.addBatch(addedIndexLabels, client);
    this.piService.removeBatch(removedIndexLabelNames, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 13 with IndexLabel

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

Example 14 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method get.

public VertexLabelEntity get(String name, int connId) {
    HugeClient client = this.client(connId);
    try {
        VertexLabel vertexLabel = client.schema().getVertexLabel(name);
        List<IndexLabel> indexLabels = client.schema().getIndexLabels();
        return join(vertexLabel, indexLabels);
    } catch (ServerException e) {
        if (e.status() == Constant.STATUS_NOT_FOUND) {
            throw new ExternalException("schema.vertexlabel.not-exist", e, name);
        }
        throw new ExternalException("schema.vertexlabel.get.failed", e, name);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ServerException(com.baidu.hugegraph.exception.ServerException) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 15 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method add.

public void add(VertexLabelEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    try {
        client.schema().addVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.create.failed", e, entity.getName());
    }
    List<IndexLabel> indexLabels = collectIndexLabels(entity, client);
    this.piService.addBatch(indexLabels, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Aggregations

IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)56 Test (org.junit.Test)34 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)11 ArrayList (java.util.ArrayList)10 ServerException (com.baidu.hugegraph.exception.ServerException)9 ExternalException (com.baidu.hugegraph.exception.ExternalException)8 Task (com.baidu.hugegraph.structure.Task)7 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)6 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)6 Date (java.util.Date)6 RestResult (com.baidu.hugegraph.rest.RestResult)4 HashSet (java.util.HashSet)4 SchemaType (com.baidu.hugegraph.entity.schema.SchemaType)2 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)2 TasksWithPage (com.baidu.hugegraph.api.task.TasksWithPage)1 Constant (com.baidu.hugegraph.common.Constant)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1