use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.
the class VertexLabelService method convert.
private static VertexLabel convert(VertexLabelUpdateEntity entity, HugeClient client) {
if (entity == null) {
return null;
}
Set<String> properties = new HashSet<>();
if (entity.getAppendProperties() != null) {
entity.getAppendProperties().forEach(p -> {
properties.add(p.getName());
});
}
VertexLabel.Builder builder;
builder = client.schema().vertexLabel(entity.getName()).properties(toStringArray(properties)).nullableKeys(toStringArray(properties));
VertexLabel vertexLabel = builder.build();
Map<String, Object> userdata = vertexLabel.userdata();
/*
* The style requires the front end to pass in the full amount
* TODO: use builder or setter, now use builder throw exception
* "Can't access builder which is completed"
*/
VertexLabelStyle style = entity.getStyle();
if (style != null) {
userdata.put(USER_KEY_STYLE, JsonUtil.toJson(style));
}
return vertexLabel;
}
use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.
the class RestoreManager method initPrimaryKeyVLs.
private void initPrimaryKeyVLs() {
if (this.primaryKeyVLs != null) {
return;
}
this.primaryKeyVLs = new HashMap<>();
List<VertexLabel> vertexLabels = this.client.schema().getVertexLabels();
for (VertexLabel vl : vertexLabels) {
if (vl.idStrategy() == IdStrategy.PRIMARY_KEY) {
this.primaryKeyVLs.put(vl.name(), vl.id());
}
}
}
use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.
the class VertexLabelAPI method checkCreateOrUpdate.
@Override
protected Object checkCreateOrUpdate(SchemaElement schemaElement) {
VertexLabel vertexLabel = (VertexLabel) schemaElement;
if (vertexLabel.idStrategy().isCustomizeUuid()) {
this.client.checkApiVersion("0.46", "customize UUID strategy");
}
Object vl = vertexLabel;
if (this.client.apiVersionLt("0.54")) {
E.checkArgument(vertexLabel.ttl() == 0L && vertexLabel.ttlStartTime() == null, "Not support ttl until api version 0.54");
vl = vertexLabel.switchV53();
}
return vl;
}
use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.
the class ParseTaskBuilder method buildTask.
private ParseTask buildTask(ElementBuilder builder, List<Line> lines) {
final LoadMetrics metrics = this.context.summary().metrics(this.struct);
final int batchSize = this.context.options().batchSize;
final ElementMapping mapping = builder.mapping();
final boolean needRemoveId = builder instanceof VertexBuilder && ((VertexLabel) builder.schemaLabel()).idStrategy().isPrimaryKey();
return new ParseTask(mapping, () -> {
List<List<Record>> batches = new ArrayList<>();
// One batch record
List<Record> records = new ArrayList<>(batchSize);
int count = 0;
for (Line line : lines) {
try {
// NOTE: don't remove entry in keyValues
@SuppressWarnings("unchecked") List<GraphElement> elements = builder.build(line.names(), line.values());
E.checkState(elements.size() <= batchSize, "The number of columns in a line cannot " + "exceed the size of a batch, but got %s > %s", elements.size(), batchSize);
// Prevent batch size from exceeding limit
if (records.size() + elements.size() > batchSize) {
LOG.debug("Create a new batch for {}", mapping);
// Add current batch and create a new batch
batches.add(records);
records = new ArrayList<>(batchSize);
}
for (GraphElement element : elements) {
if (needRemoveId) {
((Vertex) element).id(null);
}
records.add(new Record(line.rawLine(), element));
count++;
}
} catch (IllegalArgumentException e) {
metrics.increaseParseFailure(mapping);
ParseException pe = new ParseException(line.rawLine(), e);
this.handleParseFailure(mapping, pe);
}
}
if (!records.isEmpty()) {
batches.add(records);
}
metrics.plusParseSuccess(mapping, count);
return batches;
});
}
use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadVertexLabels.
@Test
public void testReadVertexLabels() {
String json = "{\"vertexlabels\": [" + "{" + "\"id\": 1," + "\"primary_keys\": [\"name\"]," + "\"index_labels\": []," + "\"name\": \"software\"," + "\"id_strategy\": \"PRIMARY_KEY\"," + "\"properties\": [\"price\", \"name\", \"lang\"]" + "}," + "{" + "\"id\": 2," + "\"primary_keys\": []," + "\"index_labels\": []," + "\"name\": \"person\"," + "\"id_strategy\": \"CUSTOMIZE_STRING\"," + "\"properties\": [\"city\", \"name\", \"age\"]" + "}" + "]}";
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<VertexLabel> vertexLabels = result.readList("vertexlabels", VertexLabel.class);
Assert.assertEquals(2, vertexLabels.size());
VertexLabel vertexLabel1 = vertexLabels.get(0);
VertexLabel vertexLabel2 = vertexLabels.get(1);
Assert.assertEquals("software", vertexLabel1.name());
Assert.assertEquals(IdStrategy.PRIMARY_KEY, vertexLabel1.idStrategy());
Assert.assertEquals(ImmutableList.of("name"), vertexLabel1.primaryKeys());
Assert.assertEquals(ImmutableSet.of("price", "name", "lang"), vertexLabel1.properties());
Assert.assertEquals("person", vertexLabel2.name());
Assert.assertEquals(IdStrategy.CUSTOMIZE_STRING, vertexLabel2.idStrategy());
Assert.assertEquals(Collections.emptyList(), vertexLabel2.primaryKeys());
Assert.assertEquals(ImmutableSet.of("city", "name", "age"), vertexLabel2.properties());
}
Aggregations