use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class TraversalUtil method convIn2Relation.
public static Condition convIn2Relation(HugeGraph graph, HugeType type, HasContainer has) {
BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
assert bp instanceof Contains;
Collection<?> values = (Collection<?>) has.getValue();
String originKey = has.getKey();
if (values.size() > 1) {
E.checkArgument(!originKey.equals(T.key.getAccessor()) && !originKey.equals(T.value.getAccessor()), "Not support hasKey() or hasValue() with " + "multiple values");
}
HugeKeys hugeKey = token2HugeKey(originKey);
List<?> valueList;
if (hugeKey != null) {
valueList = convSysListValueIfNeeded(graph, type, hugeKey, values);
switch((Contains) bp) {
case within:
return Condition.in(hugeKey, valueList);
case without:
return Condition.nin(hugeKey, valueList);
default:
throw newUnsupportedPredicate(has.getPredicate());
}
} else {
valueList = new ArrayList<>(values);
String key = has.getKey();
PropertyKey pkey = graph.propertyKey(key);
switch((Contains) bp) {
case within:
return Condition.in(pkey.id(), valueList);
case without:
return Condition.nin(pkey.id(), valueList);
default:
throw newUnsupportedPredicate(has.getPredicate());
}
}
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class TraversalUtil method convPredicateValue.
private static void convPredicateValue(HugeGraph graph, HasContainer has) {
// No need to convert if key is sysprop
if (isSysProp(has.getKey())) {
return;
}
PropertyKey pkey = graph.propertyKey(has.getKey());
updatePredicateValue(has.getPredicate(), pkey);
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class MultiGraphsTest method testCopySchemaWithMultiGraphs.
@Test
public void testCopySchemaWithMultiGraphs() {
List<HugeGraph> graphs = openGraphs("schema_g1", "schema_g2");
for (HugeGraph graph : graphs) {
graph.initBackend();
}
HugeGraph g1 = graphs.get(0);
g1.serverStarted(IdGenerator.of("server-g2"), NodeRole.MASTER);
HugeGraph g2 = graphs.get(1);
g2.serverStarted(IdGenerator.of("server-g3"), NodeRole.MASTER);
SchemaManager schema = g1.schema();
schema.propertyKey("id").asInt().create();
schema.propertyKey("name").asText().create();
schema.propertyKey("age").asInt().valueSingle().create();
schema.propertyKey("city").asText().create();
schema.propertyKey("weight").asDouble().valueList().create();
schema.propertyKey("born").asDate().ifNotExist().create();
schema.propertyKey("time").asDate().ifNotExist().create();
schema.vertexLabel("person").properties("id", "name", "age", "city", "weight", "born").primaryKeys("id").create();
schema.vertexLabel("person2").properties("id", "name", "age", "city").primaryKeys("id").create();
schema.edgeLabel("friend").sourceLabel("person").targetLabel("person").properties("time").create();
schema.indexLabel("personByName").onV("person").secondary().by("name").create();
schema.indexLabel("personByCity").onV("person").search().by("city").create();
schema.indexLabel("personByAge").onV("person").range().by("age").create();
schema.indexLabel("friendByTime").onE("friend").range().by("time").create();
Assert.assertFalse(g2.existsPropertyKey("id"));
Assert.assertFalse(g2.existsPropertyKey("name"));
Assert.assertFalse(g2.existsPropertyKey("age"));
Assert.assertFalse(g2.existsPropertyKey("city"));
Assert.assertFalse(g2.existsPropertyKey("weight"));
Assert.assertFalse(g2.existsPropertyKey("born"));
Assert.assertFalse(g2.existsPropertyKey("time"));
Assert.assertFalse(g2.existsVertexLabel("person"));
Assert.assertFalse(g2.existsVertexLabel("person2"));
Assert.assertFalse(g2.existsEdgeLabel("friend"));
Assert.assertFalse(g2.existsIndexLabel("personByName"));
Assert.assertFalse(g2.existsIndexLabel("personByCity"));
Assert.assertFalse(g2.existsIndexLabel("personByAge"));
Assert.assertFalse(g2.existsIndexLabel("friendByTime"));
// Copy schema from g1 to g2
g2.schema().copyFrom(g1.schema());
Assert.assertTrue(g2.existsPropertyKey("id"));
Assert.assertTrue(g2.existsPropertyKey("name"));
Assert.assertTrue(g2.existsPropertyKey("age"));
Assert.assertTrue(g2.existsPropertyKey("city"));
Assert.assertTrue(g2.existsPropertyKey("weight"));
Assert.assertTrue(g2.existsPropertyKey("born"));
Assert.assertTrue(g2.existsPropertyKey("time"));
Assert.assertTrue(g2.existsVertexLabel("person"));
Assert.assertTrue(g2.existsVertexLabel("person2"));
Assert.assertTrue(g2.existsEdgeLabel("friend"));
Assert.assertTrue(g2.existsIndexLabel("personByName"));
Assert.assertTrue(g2.existsIndexLabel("personByCity"));
Assert.assertTrue(g2.existsIndexLabel("personByAge"));
Assert.assertTrue(g2.existsIndexLabel("friendByTime"));
for (PropertyKey copied : g2.schema().getPropertyKeys()) {
PropertyKey origin = g1.schema().getPropertyKey(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (VertexLabel copied : schema.getVertexLabels()) {
VertexLabel origin = g1.schema().getVertexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (EdgeLabel copied : schema.getEdgeLabels()) {
EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (IndexLabel copied : schema.getIndexLabels()) {
IndexLabel origin = g1.schema().getIndexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
// Copy schema again from g1 to g2 (ignore identical content)
g2.schema().copyFrom(g1.schema());
for (PropertyKey copied : g2.schema().getPropertyKeys()) {
PropertyKey origin = g1.schema().getPropertyKey(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (VertexLabel copied : schema.getVertexLabels()) {
VertexLabel origin = g1.schema().getVertexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (EdgeLabel copied : schema.getEdgeLabels()) {
EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (IndexLabel copied : schema.getIndexLabels()) {
IndexLabel origin = g1.schema().getIndexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (HugeGraph graph : graphs) {
graph.clearBackend();
}
destroyGraphs(graphs);
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyCoreTest method testAddPropertyKeyWithAggregateType.
@Test
public void testAddPropertyKeyWithAggregateType() {
SchemaManager schema = graph().schema();
PropertyKey startTime = schema.propertyKey("startTime").asDate().valueSingle().calcMin().ifNotExist().create();
Assert.assertEquals(DataType.DATE, startTime.dataType());
Assert.assertEquals(Cardinality.SINGLE, startTime.cardinality());
Assert.assertEquals(AggregateType.MIN, startTime.aggregateType());
startTime = schema.getPropertyKey("startTime");
Assert.assertEquals(DataType.DATE, startTime.dataType());
Assert.assertEquals(Cardinality.SINGLE, startTime.cardinality());
Assert.assertEquals(AggregateType.MIN, startTime.aggregateType());
PropertyKey endTime = schema.propertyKey("endTime").asDate().valueSingle().calcMax().ifNotExist().create();
Assert.assertEquals(DataType.DATE, endTime.dataType());
Assert.assertEquals(Cardinality.SINGLE, endTime.cardinality());
Assert.assertEquals(AggregateType.MAX, endTime.aggregateType());
endTime = schema.getPropertyKey("endTime");
Assert.assertEquals(DataType.DATE, endTime.dataType());
Assert.assertEquals(Cardinality.SINGLE, endTime.cardinality());
Assert.assertEquals(AggregateType.MAX, endTime.aggregateType());
PropertyKey times = schema.propertyKey("times").asLong().valueSingle().calcSum().ifNotExist().create();
Assert.assertEquals(DataType.LONG, times.dataType());
Assert.assertEquals(Cardinality.SINGLE, times.cardinality());
Assert.assertEquals(AggregateType.SUM, times.aggregateType());
times = schema.getPropertyKey("times");
Assert.assertEquals(DataType.LONG, times.dataType());
Assert.assertEquals(Cardinality.SINGLE, times.cardinality());
Assert.assertEquals(AggregateType.SUM, times.aggregateType());
PropertyKey oldProp = schema.propertyKey("oldProp").asLong().valueSingle().calcOld().ifNotExist().create();
Assert.assertEquals(DataType.LONG, oldProp.dataType());
Assert.assertEquals(Cardinality.SINGLE, oldProp.cardinality());
Assert.assertEquals(AggregateType.OLD, oldProp.aggregateType());
oldProp = schema.getPropertyKey("oldProp");
Assert.assertEquals(DataType.LONG, oldProp.dataType());
Assert.assertEquals(Cardinality.SINGLE, oldProp.cardinality());
Assert.assertEquals(AggregateType.OLD, oldProp.aggregateType());
PropertyKey setProp = schema.propertyKey("setProp").asLong().valueSet().calcSet().ifNotExist().create();
Assert.assertEquals(DataType.LONG, setProp.dataType());
Assert.assertEquals(Cardinality.SET, setProp.cardinality());
Assert.assertEquals(AggregateType.SET, setProp.aggregateType());
setProp = schema.getPropertyKey("setProp");
Assert.assertEquals(DataType.LONG, setProp.dataType());
Assert.assertEquals(Cardinality.SET, setProp.cardinality());
Assert.assertEquals(AggregateType.SET, setProp.aggregateType());
PropertyKey listProp = schema.propertyKey("listProp").asLong().valueList().calcList().ifNotExist().create();
Assert.assertEquals(DataType.LONG, listProp.dataType());
Assert.assertEquals(Cardinality.LIST, listProp.cardinality());
Assert.assertEquals(AggregateType.LIST, listProp.aggregateType());
listProp = schema.getPropertyKey("listProp");
Assert.assertEquals(DataType.LONG, listProp.dataType());
Assert.assertEquals(Cardinality.LIST, listProp.cardinality());
Assert.assertEquals(AggregateType.LIST, listProp.aggregateType());
PropertyKey regular = schema.propertyKey("regular").create();
Assert.assertEquals(DataType.TEXT, regular.dataType());
Assert.assertEquals(Cardinality.SINGLE, regular.cardinality());
Assert.assertEquals(AggregateType.NONE, regular.aggregateType());
regular = schema.getPropertyKey("regular");
Assert.assertEquals(DataType.TEXT, regular.dataType());
Assert.assertEquals(Cardinality.SINGLE, regular.cardinality());
Assert.assertEquals(AggregateType.NONE, regular.aggregateType());
}
use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.
the class PropertyKeyCoreTest method testClearOlapPropertyKey.
@Test
public void testClearOlapPropertyKey() {
Assume.assumeTrue("Not support olap properties", storeFeatures().supportsOlapProperties());
SchemaManager schema = graph().schema();
PropertyKey olap = schema.propertyKey("olap").asText().valueSingle().writeType(WriteType.OLAP_COMMON).ifNotExist().create();
Assert.assertEquals("olap", olap.name());
Assert.assertEquals(DataType.TEXT, olap.dataType());
Assert.assertEquals(Cardinality.SINGLE, olap.cardinality());
Assert.assertEquals(WriteType.OLAP_COMMON, olap.writeType());
graph().clearPropertyKey(olap);
olap = graph().propertyKey("olap");
Assert.assertEquals("olap", olap.name());
Assert.assertEquals(DataType.TEXT, olap.dataType());
Assert.assertEquals(Cardinality.SINGLE, olap.cardinality());
Assert.assertEquals(WriteType.OLAP_COMMON, olap.writeType());
PropertyKey pagerank = schema.propertyKey("pagerank").asDouble().valueSingle().writeType(WriteType.OLAP_RANGE).ifNotExist().create();
Assert.assertEquals("pagerank", pagerank.name());
Assert.assertEquals(DataType.DOUBLE, pagerank.dataType());
Assert.assertEquals(Cardinality.SINGLE, pagerank.cardinality());
Assert.assertEquals(WriteType.OLAP_RANGE, pagerank.writeType());
graph().clearPropertyKey(pagerank);
pagerank = graph().propertyKey("pagerank");
Assert.assertEquals("pagerank", pagerank.name());
Assert.assertEquals(DataType.DOUBLE, pagerank.dataType());
Assert.assertEquals(Cardinality.SINGLE, pagerank.cardinality());
Assert.assertEquals(WriteType.OLAP_RANGE, pagerank.writeType());
PropertyKey wcc = schema.propertyKey("wcc").asText().valueSingle().writeType(WriteType.OLAP_SECONDARY).ifNotExist().create();
Assert.assertEquals("wcc", wcc.name());
Assert.assertEquals(DataType.TEXT, wcc.dataType());
Assert.assertEquals(Cardinality.SINGLE, wcc.cardinality());
Assert.assertEquals(WriteType.OLAP_SECONDARY, wcc.writeType());
graph().clearPropertyKey(wcc);
wcc = graph().propertyKey("wcc");
Assert.assertEquals("wcc", wcc.name());
Assert.assertEquals(DataType.TEXT, wcc.dataType());
Assert.assertEquals(Cardinality.SINGLE, wcc.cardinality());
Assert.assertEquals(WriteType.OLAP_SECONDARY, wcc.writeType());
}
Aggregations