Search in sources :

Example 6 with IndexLabel

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

the class IndexLabelApiTest method testList.

@Test
public void testList() {
    IndexLabel indexLabel1 = indexLabelAPI.create(fillIndexLabel.apply("personByAge")).indexLabel();
    IndexLabel indexLabel2 = schema().indexLabel("personByCity").onV("person").by("city").secondary().build();
    indexLabel2 = indexLabelAPI.create(indexLabel2).indexLabel();
    List<IndexLabel> indexLabels = indexLabelAPI.list();
    Assert.assertEquals(2, indexLabels.size());
    assertContains(indexLabels, indexLabel1);
    assertContains(indexLabels, indexLabel2);
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 7 with IndexLabel

use of com.baidu.hugegraph.structure.schema.IndexLabel 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 8 with IndexLabel

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

the class EdgeLabelService method reuse.

public void reuse(ConflictDetail detail, int connId) {
    Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
    HugeClient client = this.client(connId);
    List<PropertyKey> propertyKeys = this.pkService.filter(detail, client);
    if (!propertyKeys.isEmpty()) {
        try {
            this.pkService.addBatch(propertyKeys, client);
        } catch (Exception e) {
            throw new ExternalException("schema.propertykey.reuse.failed", e);
        }
    }
    List<VertexLabel> vertexLabels = this.vlService.filter(detail, client);
    if (!vertexLabels.isEmpty()) {
        try {
            this.vlService.addBatch(vertexLabels, client);
        } catch (Exception e) {
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.vertexlabel.reuse.failed", e);
        }
    }
    List<EdgeLabel> edgeLabels = this.filter(detail, client);
    if (!edgeLabels.isEmpty()) {
        try {
            this.addBatch(edgeLabels, client);
        } catch (Exception e) {
            this.vlService.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.edgelabel.reuse.failed", e);
        }
    }
    List<IndexLabel> indexLabels = this.piService.filter(detail, client);
    if (!indexLabels.isEmpty()) {
        try {
            this.piService.addBatch(indexLabels, client);
        } catch (Exception e) {
            this.removeBatch(edgeLabels, client);
            this.vlService.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.propertyindex.reuse.failed", e);
        }
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 9 with IndexLabel

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

the class EdgeLabelService method add.

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

Example 10 with IndexLabel

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

the class EdgeLabelService method update.

public void update(EdgeLabelUpdateEntity entity, int connId) {
    HugeClient client = this.client(connId);
    EdgeLabel edgeLabel = 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, false, entity.getName());
    List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
    if (addedIndexLabelNames != null) {
        for (String name : addedIndexLabelNames) {
            if (existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.edgelabel.update.append-index-existed", entity.getName(), name);
            }
        }
    }
    if (removedIndexLabelNames != null) {
        for (String name : removedIndexLabelNames) {
            if (!existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.edgelabel.update.remove-index-unexisted", entity.getName(), name);
            }
        }
    }
    try {
        // NOTE: property can append but doesn't support eliminate now
        client.schema().appendEdgeLabel(edgeLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.edgelabel.update.failed", e, entity.getName());
    }
    this.piService.addBatch(addedIndexLabels, client);
    this.piService.removeBatch(removedIndexLabelNames, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) 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