Search in sources :

Example 36 with IndexLabel

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

the class SchemaService method collectPropertyIndexes.

public static List<PropertyIndex> collectPropertyIndexes(SchemaLabel schemaLabel, List<IndexLabel> indexLabels) {
    List<PropertyIndex> propertyIndexes = new ArrayList<>();
    if (indexLabels == null) {
        return propertyIndexes;
    }
    for (IndexLabel indexLabel : indexLabels) {
        if (indexLabel.baseType().string().equals(schemaLabel.type()) && indexLabel.baseValue().equals(schemaLabel.name())) {
            SchemaType schemaType = SchemaType.convert(indexLabel.baseType());
            PropertyIndex propertyIndex;
            propertyIndex = new PropertyIndex(indexLabel.baseValue(), schemaType, indexLabel.name(), indexLabel.indexType(), indexLabel.indexFields());
            propertyIndexes.add(propertyIndex);
        }
    }
    return propertyIndexes;
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex) SchemaType(com.baidu.hugegraph.entity.schema.SchemaType)

Example 37 with IndexLabel

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

the class SchemaService method convertIndexLabels.

public static List<IndexLabel> convertIndexLabels(List<PropertyIndex> entities, HugeClient client, boolean isVertex, String baseValue) {
    if (CollectionUtils.isEmpty(entities)) {
        return Collections.emptyList();
    }
    List<IndexLabel> indexLabels = new ArrayList<>(entities.size());
    SchemaManager schema = client.schema();
    for (PropertyIndex index : entities) {
        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 38 with IndexLabel

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

the class VertexLabelService method reuse.

public void reuse(ConflictDetail detail, int connId) {
    // Assume that the conflict detail is valid
    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.filter(detail, client);
    // Filter propertykeys and propertyindexes
    if (!vertexLabels.isEmpty()) {
        try {
            this.addBatch(vertexLabels, client);
        } catch (Exception e) {
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.vertexlabel.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(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) 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 39 with IndexLabel

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

the class RestResultTest method testReadIndexLabels.

@Test
public void testReadIndexLabels() {
    String json = "{\"indexlabels\": [" + "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}," + "{" + "\"id\": \"4\"," + "\"index_type\": \"SECONDARY\"," + "\"base_value\": \"person\"," + "\"name\": \"personByName\"," + "\"fields\": [\"name\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}" + "]}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult result = new RestResult(this.mockResponse);
    Assert.assertEquals(200, result.status());
    Assert.assertNull(result.headers());
    List<IndexLabel> indexLabels = result.readList("indexlabels", IndexLabel.class);
    Assert.assertEquals(2, indexLabels.size());
    IndexLabel indexLabel1 = indexLabels.get(0);
    IndexLabel indexLabel2 = indexLabels.get(1);
    Assert.assertEquals("softwareByPrice", indexLabel1.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel1.baseType());
    Assert.assertEquals("software", indexLabel1.baseValue());
    Assert.assertEquals(IndexType.SEARCH, indexLabel1.indexType());
    Assert.assertEquals(ImmutableList.of("price"), indexLabel1.indexFields());
    Assert.assertEquals("personByName", indexLabel2.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel2.baseType());
    Assert.assertEquals("person", indexLabel2.baseValue());
    Assert.assertEquals(IndexType.SECONDARY, indexLabel2.indexType());
    Assert.assertEquals(ImmutableList.of("name"), indexLabel2.indexFields());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 40 with IndexLabel

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

the class IndexLabelTest method testIndexLabelV49.

@Test
public void testIndexLabelV49() {
    IndexLabel.Builder builder = new IndexLabel.BuilderImpl("personByAge", null);
    IndexLabel indexLabel = builder.onV("person").secondary().by("age").build();
    IndexLabel.IndexLabelV49 indexLabelV49 = indexLabel.switchV49();
    // Without userdata
    String json = "{\"id\":0,\"name\":\"personByAge\"," + "\"check_exist\":true,\"base_type\":\"VERTEX_LABEL\"," + "\"base_value\":\"person\"," + "\"index_type\":\"SECONDARY\",\"fields\":[\"age\"]}";
    Assert.assertEquals(json, JsonUtil.toJson(indexLabelV49));
    Assert.assertEquals(HugeType.INDEX_LABEL.string(), indexLabelV49.type());
    Assert.assertThrows(NotSupportException.class, () -> {
        indexLabelV49.userdata();
    });
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

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