Search in sources :

Example 6 with PropertyKey

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

the class JanusGraphIndexTest method testWidcardQuery.

/**
 * Tests indexing using _all virtual field
 */
@Test
public void testWidcardQuery() {
    if (supportsWildcardQuery()) {
        PropertyKey p1 = makeKey("p1", String.class);
        PropertyKey p2 = makeKey("p2", String.class);
        mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX);
        finishSchema();
        clopen();
        JanusGraphVertex v1 = graph.addVertex();
        v1.property("p1", "test1");
        v1.property("p2", "test2");
        // Flush the index
        clopen();
        assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertexStream().findFirst().orElseThrow(IllegalStateException::new).getElement());
        assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertexStream().findFirst().orElseThrow(IllegalStateException::new).getElement());
    }
}
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 7 with PropertyKey

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

the class JanusGraphIndexTest method testListUpdate.

@Test
public void testListUpdate() {
    if (!indexFeatures.supportsCardinality(Cardinality.LIST)) {
        return;
    }
    PropertyKey name = makeKey("name", String.class);
    if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) {
    }
    PropertyKey alias = mgmt.makePropertyKey("alias").dataType(String.class).cardinality(Cardinality.LIST).make();
    mgmt.buildIndex("namev", Vertex.class).addKey(name).addKey(alias, indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ? Mapping.TEXTSTRING.asParameter() : Mapping.DEFAULT.asParameter()).buildMixedIndex(INDEX);
    finishSchema();
    JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez");
    assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
    clopen();
    assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
    v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
    v.property(VertexProperty.Cardinality.list, "alias", "Marko");
    assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
    clopen();
    assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
    v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
    v.property(VertexProperty.Cardinality.list, "alias", "mRodriguez");
    assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
    clopen();
    assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
    assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
    if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) {
        assertCount(1, tx.query().has("alias", Cmp.EQUAL, "Marko").vertices());
        assertCount(1, tx.query().has("alias", Cmp.EQUAL, "mRodriguez").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 8 with PropertyKey

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

the class JanusGraphIndexTest method testIndexReplay.

@Category({ BrittleTests.class })
@Test
public void testIndexReplay() throws Exception {
    final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    final Instant startTime = times.getTime();
    clopen(option(SYSTEM_LOG_TRANSACTIONS), true, option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250), option(MAX_COMMIT_TIME), Duration.ofSeconds(1), option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300), option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX), option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName(), option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true);
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
    mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX);
    finishSchema();
    Vertex[] vs = new JanusGraphVertex[4];
    vs[0] = tx.addVertex("name", "Big Boy Bobson", "age", 55);
    newTx();
    vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35);
    vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75);
    vs[3] = tx.addVertex("name", "Long John Don", "age", 15);
    newTx();
    vs[2] = getV(tx, vs[2]);
    vs[2].remove();
    vs[3] = getV(tx, vs[3]);
    vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
    vs[3].property("age").remove();
    newTx();
    vs[0] = getV(tx, vs[0]);
    vs[0].property(VertexProperty.Cardinality.single, "age", 66);
    newTx();
    clopen();
    // Just to make sure nothing has been persisted to index
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    /*
        Transaction Recovery
         */
    TransactionRecovery recovery = JanusGraphFactory.startTransactionRecovery(graph, startTime);
    // wait
    Thread.sleep(12000L);
    recovery.shutdown();
    long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();
    clopen();
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    // JanusGraphVertex v = Iterables.getOnlyElement(tx.query().has("name",Text.CONTAINS,"long").vertices());
    // System.out.println(v.getProperty("age"));
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long").interval("age", 30, 40), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("age", 75), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy").interval("age", 60, 70), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().interval("age", 0, 100), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    // schema transaction was successful
    assertEquals(1, recoveryStats[0]);
    // all 4 index transaction had provoked errors in the indexing backend
    assertEquals(4, recoveryStats[1]);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) PropertyKey(org.janusgraph.core.PropertyKey) Category(org.junit.experimental.categories.Category) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Test(org.junit.Test)

Example 9 with PropertyKey

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

the class JanusGraphIndexTest method testCompositeAndMixedIndexing.

@Test
public void testCompositeAndMixedIndexing() {
    PropertyKey name = makeKey("name", String.class);
    PropertyKey weight = makeKey("weight", Double.class);
    PropertyKey text = makeKey("text", String.class);
    makeKey("flag", Boolean.class);
    JanusGraphIndex composite = mgmt.buildIndex("composite", Vertex.class).addKey(name).addKey(weight).buildCompositeIndex();
    JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
    mixed.name();
    composite.name();
    finishSchema();
    final int numV = 100;
    String[] strings = { "houseboat", "humanoid", "differential", "extraordinary" };
    String[] stringsTwo = new String[strings.length];
    for (int i = 0; i < strings.length; i++) stringsTwo[i] = strings[i] + " " + strings[i];
    final int modulo = 5;
    final int divisor = modulo * strings.length;
    for (int i = 0; i < numV; i++) {
        JanusGraphVertex v = tx.addVertex();
        v.property("name", strings[i % strings.length]);
        v.property("text", strings[i % strings.length]);
        v.property("weight", (i % modulo) + 0.5);
        v.property("flag", true);
    }
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("flag"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
    clopen();
    // Same queries as above
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("flag"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 10 with PropertyKey

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

the class JanusGraphIndexTest method testDualMapping.

@Test
public void testDualMapping() {
    if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING))
        return;
    PropertyKey name = makeKey("name", String.class);
    JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX);
    mixed.name();
    finishSchema();
    tx.addVertex("name", "Long John Don");
    tx.addVertex("name", "Long Little Lewis");
    tx.addVertex("name", "Middle Sister Mabel");
    clopen();
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.FUZZY, "Long john Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_FUZZY, "Midle"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    for (final Vertex u : tx.getVertices()) {
        final String n = u.value("name");
        if (n.endsWith("Don")) {
            u.remove();
        } else if (n.endsWith("Lewis")) {
            u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
        } else if (n.endsWith("Mabel")) {
            u.property("name").remove();
        }
    }
    clopen();
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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