Search in sources :

Example 21 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphTest method evaluateQuery.

public static void evaluateQuery(JanusGraphQuery query, ElementCategory resultType, int expectedResults, boolean[] subQuerySpecs, Map<PropertyKey, Order> orderMap, String... intersectingIndexes) {
    if (intersectingIndexes == null)
        intersectingIndexes = new String[0];
    SimpleQueryProfiler profiler = new SimpleQueryProfiler();
    ((GraphCentricQueryBuilder) query).profiler(profiler);
    Iterable<? extends JanusGraphElement> result;
    switch(resultType) {
        case PROPERTY:
            result = query.properties();
            break;
        case EDGE:
            result = query.edges();
            break;
        case VERTEX:
            result = query.vertices();
            break;
        default:
            throw new AssertionError();
    }
    OrderList orders = profiler.getAnnotation(QueryProfiler.ORDERS_ANNOTATION);
    // Check elements and that they are returned in the correct order
    int no = 0;
    JanusGraphElement previous = null;
    for (JanusGraphElement e : result) {
        assertNotNull(e);
        no++;
        if (previous != null && !orders.isEmpty()) {
            assertTrue(orders.compare(previous, e) <= 0);
        }
        previous = e;
    }
    assertEquals(expectedResults, no);
    // Check OrderList of query
    assertNotNull(orders);
    assertEquals(orderMap.size(), orders.size());
    for (int i = 0; i < orders.size(); i++) {
        assertEquals(orderMap.get(orders.getKey(i)), orders.getOrder(i));
    }
    for (PropertyKey key : orderMap.keySet()) assertTrue(orders.containsKey(key));
    // Check subqueries
    SimpleQueryProfiler simpleQueryProfiler = Iterables.getOnlyElement(StreamSupport.stream(profiler.spliterator(), false).filter(p -> !p.getGroupName().equals(QueryProfiler.OPTIMIZATION)).collect(Collectors.toList()));
    if (subQuerySpecs.length == 2) {
        // 0=>fitted, 1=>ordered
        assertEquals(subQuerySpecs[0], simpleQueryProfiler.getAnnotation(QueryProfiler.FITTED_ANNOTATION));
        assertEquals(subQuerySpecs[1], simpleQueryProfiler.getAnnotation(QueryProfiler.ORDERED_ANNOTATION));
    }
    Set<String> indexNames = new HashSet<>();
    int indexQueries = 0;
    boolean fullScan = false;
    for (SimpleQueryProfiler indexProfiler : simpleQueryProfiler) {
        if (indexProfiler.getAnnotation(QueryProfiler.FULLSCAN_ANNOTATION) != null) {
            fullScan = true;
        } else {
            indexNames.add(indexProfiler.getAnnotation(QueryProfiler.INDEX_ANNOTATION));
            indexQueries++;
        }
    }
    if (indexQueries > 0)
        assertFalse(fullScan);
    if (fullScan)
        assertTrue(intersectingIndexes.length == 0);
    assertEquals(intersectingIndexes.length, indexQueries);
    assertEquals(Sets.newHashSet(intersectingIndexes), indexNames);
}
Also used : GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) JanusGraphElement(org.janusgraph.core.JanusGraphElement) OrderList(org.janusgraph.graphdb.internal.OrderList) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) PropertyKey(org.janusgraph.core.PropertyKey) HashSet(java.util.HashSet)

Example 22 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphTest method testRelationTypeIndexes.

@Test
public void testRelationTypeIndexes() {
    PropertyKey weight = makeKey("weight", Float.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make();
    EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(time).make();
    EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make();
    EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make();
    RelationTypeIndex name1 = mgmt.buildPropertyIndex(name, "weightDesc", weight);
    RelationTypeIndex connect1 = mgmt.buildEdgeIndex(connect, "weightAsc", Direction.BOTH, incr, weight);
    RelationTypeIndex connect2 = mgmt.buildEdgeIndex(connect, "weightDesc", Direction.OUT, decr, weight);
    RelationTypeIndex connect3 = mgmt.buildEdgeIndex(connect, "time+weight", Direction.OUT, decr, time, weight);
    RelationTypeIndex child1 = mgmt.buildEdgeIndex(child, "time", Direction.OUT, time);
    RelationTypeIndex link1 = mgmt.buildEdgeIndex(link, "time", Direction.OUT, time);
    final String name1n = name1.name(), connect1n = connect1.name(), connect2n = connect2.name(), connect3n = connect3.name(), child1n = child1.name(), link1n = link1.name();
    // ########### INSPECTION & FAILURE ##############
    assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
    assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
    assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
    assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
    assertNotNull(mgmt.getRelationIndex(link, "time"));
    assertNull(mgmt.getRelationIndex(name, "time"));
    assertEquals(1, Iterables.size(mgmt.getRelationIndexes(child)));
    assertEquals(3, Iterables.size(mgmt.getRelationIndexes(connect)));
    assertEquals(0, Iterables.size(mgmt.getRelationIndexes(weight)));
    try {
        // Name already exists
        mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    // } catch (IllegalArgumentException e) {}
    try {
        // Not valid in this direction due to multiplicity constraint
        mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Not valid in this direction due to unidirectionality
        mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // ########## END INSPECTION ###########
    finishSchema();
    weight = mgmt.getPropertyKey("weight");
    time = mgmt.getPropertyKey("time");
    name = mgmt.getPropertyKey("name");
    connect = mgmt.getEdgeLabel("connect");
    child = mgmt.getEdgeLabel("child");
    link = mgmt.getEdgeLabel("link");
    // ########### INSPECTION & FAILURE (copied from above) ##############
    assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
    assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
    assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
    assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
    assertNotNull(mgmt.getRelationIndex(link, "time"));
    assertNull(mgmt.getRelationIndex(name, "time"));
    assertEquals(1, Iterables.size(mgmt.getRelationIndexes(child)));
    assertEquals(3, Iterables.size(mgmt.getRelationIndexes(connect)));
    assertEquals(0, Iterables.size(mgmt.getRelationIndexes(weight)));
    try {
        // Name already exists
        mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    // } catch (IllegalArgumentException e) {}
    try {
        // Not valid in this direction due to multiplicity constraint
        mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Not valid in this direction due to unidirectionality
        mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // ########## END INSPECTION ###########
    mgmt.rollback();
    /*
        ########## TEST WITHIN TRANSACTION ##################
        */
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    final int numV = 100;
    JanusGraphVertex v = tx.addVertex();
    JanusGraphVertex[] ns = new JanusGraphVertex[numV];
    for (int i = 0; i < numV; i++) {
        double w = (i * 0.5) % 5;
        long t = (i + 77) % numV;
        VertexProperty p = v.property("name", "v" + i, "weight", w, "time", t);
        ns[i] = tx.addVertex();
        for (String label : new String[] { "connect", "child", "link" }) {
            Edge e = v.addEdge(label, ns[i], "weight", w, "time", t);
        }
    }
    JanusGraphVertex u = ns[0];
    VertexList vl;
    // ######### QUERIES ##########
    v = getV(tx, v);
    u = getV(tx, u);
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
    vl = v.query().labels("child").direction(BOTH).vertexIds();
    assertEquals(numV, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
    assertEquals(2 * numV / 10, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
    vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
    assertEquals(10, vl.size());
    assertFalse(vl.isSorted());
    assertFalse(isSortedByID(vl));
    vl.sort();
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    // --------------
    clopen();
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    // ######### QUERIES (copied from above) ##########
    v = getV(tx, v);
    u = getV(tx, u);
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
    vl = v.query().labels("child").direction(BOTH).vertexIds();
    assertEquals(numV, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
    assertEquals(2 * numV / 10, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
    vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
    assertEquals(10, vl.size());
    assertFalse(vl.isSorted());
    assertFalse(isSortedByID(vl));
    vl.sort();
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    // Update in transaction
    for (Object o : v.query().labels("name").properties()) {
        JanusGraphVertexProperty<String> p = (JanusGraphVertexProperty<String>) o;
        if (p.<Long>value("time") < (numV / 2))
            p.remove();
    }
    for (Object o : v.query().direction(BOTH).edges()) {
        JanusGraphEdge e = (JanusGraphEdge) o;
        if (e.<Long>value("time") < (numV / 2))
            e.remove();
    }
    ns = new JanusGraphVertex[numV * 3 / 2];
    for (int i = numV; i < numV * 3 / 2; i++) {
        double w = (i * 0.5) % 5;
        v.property("name", "v" + i, "weight", w, "time", (long) i);
        ns[i] = tx.addVertex();
        for (String label : new String[] { "connect", "child", "link" }) {
            JanusGraphEdge e = v.addEdge(label, ns[i], "weight", w, "time", (long) i);
        }
    }
    // ######### UPDATED QUERIES ##########
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    // ######### END UPDATED QUERIES ##########
    newTx();
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    v = getV(tx, v);
    u = getV(tx, u);
    // ######### UPDATED QUERIES (copied from above) ##########
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
// ######### END UPDATED QUERIES ##########
}
Also used : JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) EdgeLabel(org.janusgraph.core.EdgeLabel) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) SchemaViolationException(org.janusgraph.core.SchemaViolationException) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) VertexList(org.janusgraph.core.VertexList) Test(org.junit.Test)

Example 23 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphTest method testPropertyTTLTiming.

@Category({ BrittleTests.class })
@Test
public void testPropertyTTLTiming() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
    mgmt.setTTL(name, Duration.ofSeconds(42));
    mgmt.setTTL(place, Duration.ofSeconds(1));
    final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    final JanusGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(2));
    assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place));
    assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
    mgmt.commit();
    JanusGraphVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");
    tx.commit();
    Object id = v1.id();
    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());
    Thread.sleep(1001);
    graph.tx().rollback();
    // short-lived property expires first
    v1 = getV(graph, id);
    assertNotNull(v1);
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertNotEmpty(graph.query().has("name", "some event").vertices());
    Thread.sleep(1001);
    graph.tx().rollback();
    // vertex expires before defined TTL of the long-lived property
    assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
    assertEmpty(graph.query().has("name", "some event").vertices());
    v1 = getV(graph, id);
    assertNull(v1);
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Category(org.junit.experimental.categories.Category) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Test(org.junit.Test)

Example 24 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphTest method testPropertyCardinality.

/* ==================================================================================
                            ADVANCED
     ==================================================================================*/
/**
 * This test exercises different types of updates against cardinality restricted properties
 * to ensure that the resulting behavior is fully consistent.
 */
@Test
public void testPropertyCardinality() {
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make();
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex();
    mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
    finishSchema();
    JanusGraphVertex v1 = tx.addVertex();
    v1.property("name", "name1");
    JanusGraphVertex v2 = tx.addVertex();
    v2.property("uid", 512);
    newTx();
    v1 = tx.getVertex(v1.longId());
    // Ensure that the old index record gets removed
    v1.property("name", "name2");
    v2 = tx.getVertex(v2.longId());
    // Ensure that replacement is allowed
    v2.property("uid", 512);
    newTx();
    assertCount(0, tx.query().has("name", "name1").vertices());
    assertCount(1, tx.query().has("name", "name2").vertices());
    assertCount(1, tx.query().has("uid", 512).vertices());
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 25 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphTest method testIndexQueryWithLabelsAndContainsIN.

@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882
    String labelName = "labelName";
    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    JanusGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();
    JanusGraphVertex foo = graph.addVertex(labelName);
    JanusGraphVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();
    Iterable<JanusGraphVertex> vertexes = graph.query().has("uid", Contain.IN, ImmutableList.of("foo", "bar")).has(LABEL_NAME, labelName).vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (JanusGraphVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
Also used : VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

PropertyKey (org.janusgraph.core.PropertyKey)84 Test (org.junit.Test)59 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)57 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)28 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)28 EdgeLabel (org.janusgraph.core.EdgeLabel)21 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)13 VertexLabel (org.janusgraph.core.VertexLabel)13 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)11 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)9 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)9 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 JanusGraph (org.janusgraph.core.JanusGraph)8 JanusGraphException (org.janusgraph.core.JanusGraphException)8 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)8 Instant (java.time.Instant)6 ExecutionException (java.util.concurrent.ExecutionException)6