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;
}
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;
}
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);
}
}
}
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());
}
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();
});
}
Aggregations