Search in sources :

Example 21 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project sqlg by pietermartin.

the class TestHasLabelAndId method testOutEWithHasLabelAndId.

@Test
public void testOutEWithHasLabelAndId() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c = this.sqlgGraph.addVertex(T.label, "C");
    Vertex c2 = this.sqlgGraph.addVertex(T.label, "C");
    Vertex d = this.sqlgGraph.addVertex(T.label, "D");
    Vertex d2 = this.sqlgGraph.addVertex(T.label, "D");
    Edge ab = b.addEdge("ab", a);
    Edge ab2 = b2.addEdge("ab", a);
    Edge ac = c.addEdge("ac", a);
    Edge ac2 = c2.addEdge("ac", a);
    Edge ad = d.addEdge("ad", a);
    Edge ad2 = d2.addEdge("ad", a);
    this.sqlgGraph.tx().commit();
    GraphTraversal<Edge, Vertex> traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV();
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(2, vertices.size());
    Assert.assertEquals(a, vertices.get(0));
    Assert.assertEquals(a, vertices.get(1));
    traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV().hasLabel("B");
    vertices = traversal.toList();
    Assert.assertEquals(0, vertices.size());
    traversal = this.sqlgGraph.traversal().E().hasLabel("ab").inV().hasLabel("A");
    vertices = traversal.toList();
    Assert.assertEquals(2, vertices.size());
    Assert.assertEquals(a, vertices.get(0));
    Assert.assertEquals(a, vertices.get(1));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).inV().hasLabel("A", "B");
    vertices = traversal.toList();
    Assert.assertEquals(6, vertices.size());
    Assert.assertTrue(vertices.stream().allMatch(v -> v.equals(a)));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B");
    vertices = traversal.toList();
    Assert.assertEquals(4, vertices.size());
    Assert.assertTrue(vertices.contains(b) && vertices.contains(b2) && vertices.contains(c) && vertices.contains(c2));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.eq(b));
    vertices = traversal.toList();
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(b, vertices.get(0));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.neq(b));
    vertices = traversal.toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(vertices.contains(b2) && vertices.contains(c) && vertices.contains(c2));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.within(b.id(), b2.id(), c.id()));
    vertices = traversal.toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(vertices.contains(b) && vertices.contains(b2) && vertices.contains(c));
    traversal = this.sqlgGraph.traversal().E().has(T.label, P.within("ab", "ac", "ad")).outV().hasLabel("C", "B").has(T.id, P.without(b.id(), b2.id(), c.id()));
    vertices = traversal.toList();
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(c2, vertices.get(0));
}
Also used : Arrays(java.util.Arrays) BaseTest(org.umlg.sqlg.test.BaseTest) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) HashSet(java.util.HashSet) List(java.util.List) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) Assert(org.junit.Assert) Collections(java.util.Collections) P(org.apache.tinkerpop.gremlin.process.traversal.P) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 22 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project janusgraph by JanusGraph.

the class JanusGraphMultiQueryStrategyTest method testMultiQuery.

@Test
public void testMultiQuery() {
    clopen(option(USE_MULTIQUERY), true);
    makeSampleGraph();
    Traversal t = g.V(sv[0]).outE().inV().choose(__.inE("knows").has("weight", 0), __.inE("knows").has("weight", 1), __.inE("knows").has("weight", 2)).profile("~metrics");
    assertNumStep(numV * 2, 2, (GraphTraversal) t, ChooseStep.class, JanusGraphVertexStep.class);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    t = g.V(sv[0]).outE().inV().union(__.inE("knows").has("weight", 0), __.inE("knows").has("weight", 1), __.inE("knows").has("weight", 2)).profile("~metrics");
    assertNumStep(numV * 6, 2, (GraphTraversal) t, UnionStep.class, JanusGraphVertexStep.class);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    // repeat starts from vertex with id 0 and goes in to the sv[0] vertex then loops back out to the vertex with the next id
    int[] loop = { 0 };
    t = g.V(vs[0], vs[1], vs[2]).repeat(__.inE("knows").outV().hasId(sv[0].id()).out(// TINKERPOP-2342
    "knows").sideEffect(e -> loop[0] = e.loops()).has("id", loop[0])).times(numV).profile("~metrics");
    assertNumStep(3, 1, (GraphTraversal) t, RepeatStep.class);
    assertEquals(numV - 1, loop[0]);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    t = g.V(vs[0], vs[1], vs[2]).optional(__.inE("knows").has("weight", 0)).profile("~metrics");
    assertNumStep(12, 1, (GraphTraversal) t, OptionalStep.class);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    t = g.V(vs[0], vs[1], vs[2]).filter(__.inE("knows").has("weight", 0)).profile("~metrics");
    assertNumStep(1, 1, (GraphTraversal) t, TraversalFilterStep.class);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    assertNumStep(superV * (numV / 5), 2, g.V().has("id", sid).outE("knows").has("weight", 1), JanusGraphStep.class, JanusGraphVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, g.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), JanusGraphStep.class, JanusGraphVertexStep.class);
    assertNumStep(superV * 10, 2, g.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), JanusGraphStep.class, JanusGraphVertexStep.class);
    assertNumStep(superV * 10, 1, g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)), JanusGraphStep.class);
    assertNumStep(superV * 10, 0, g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)), LocalStep.class);
    assertNumStep(superV * numV, 2, g.V().has("id", sid).values("names"), JanusGraphStep.class, JanusGraphPropertiesStep.class);
    // Verify traversal metrics when all reads are from cache (i.e. no backend queries)
    t = g.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", desc).limit(10)).profile("~metrics");
    assertCount(superV * 10, t);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
    // Verify that properties also use multi query
    t = g.V().has("id", sid).values("names").profile("~metrics");
    assertCount(superV * numV, t);
    assertTrue(queryProfilerAnnotationIsPresent(t, QueryProfiler.MULTIQUERY_ANNOTATION));
}
Also used : Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) ChooseStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep) JanusGraphLocalQueryOptimizerStrategy(org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphLocalQueryOptimizerStrategy) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OptionalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) Edge(org.apache.tinkerpop.gremlin.structure.Edge) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Test(org.junit.jupiter.api.Test) List(java.util.List) JanusGraphBaseTest.option(org.janusgraph.graphdb.JanusGraphBaseTest.option) JanusGraphAssert.assertNumStep(org.janusgraph.testutil.JanusGraphAssert.assertNumStep) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Test(org.junit.jupiter.api.Test)

Example 23 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project janusgraph by JanusGraph.

the class QueryTest method testMultipleIndexQueryWithLimits.

@Test
public void testMultipleIndexQueryWithLimits() {
    JanusGraphManagement mgmt = graph.openManagement();
    PropertyKey prop1Key = mgmt.makePropertyKey("prop1").dataType(String.class).make();
    PropertyKey prop2Key = mgmt.makePropertyKey("prop2").dataType(String.class).make();
    mgmt.buildIndex("prop1_idx", Vertex.class).addKey(prop1Key).buildCompositeIndex();
    mgmt.buildIndex("prop2_idx", Vertex.class).addKey(prop2Key).buildCompositeIndex();
    mgmt.commit();
    // Creates 20 vertices with prop1=prop1val1, prop2=prop2val1
    for (int i = 0; i < 20; i++) {
        tx.addVertex().property("prop1", "prop1val1").element().property("prop2", "prop2val1");
    }
    // Creates an additional vertex with prop1=prop1val1, prop2=prop2val2
    tx.addVertex().property("prop1", "prop1val1").element().property("prop2", "prop2val2");
    tx.commit();
    List<Vertex> res;
    // Tests that queries for the single vertex containing prop1=prop1val1, prop2=prop2val2, are returned when limit(1) is applied
    // Tests that single vertex containing prop1=prop1val1, prop2=prop2val2 is returned when indices are not used
    res = graph.traversal().V().map(x -> x.get()).has("prop2", "prop2val2").has("prop1", "prop1val1").limit(1).toList();
    assertEquals(1, res.size());
    // Tests that single vertex containing prop1=prop1val1, prop2=prop2val2 is returned when only prop1 index is used
    res = graph.traversal().V().has("prop1", "prop1val1").map(x -> x.get()).has("prop2", "prop2val2").limit(1).toList();
    assertEquals(1, res.size());
    // Tests that single vertex containing prop1=prop1val1, prop2=prop2val2 is returned when only prop2 index is used
    res = graph.traversal().V().has("prop2", "prop2val2").map(x -> x.get()).has("prop1", "prop1val1").limit(1).toList();
    assertEquals(1, res.size());
    // Tests that JanusGraphStep strategy properly combines has() steps to use both indices
    // Tests without limits
    res = graph.traversal().V().has("prop1", "prop1val1").has("prop2", "prop2val2").toList();
    assertEquals(1, res.size());
    // Tests with limit
    res = graph.traversal().V().has("prop1", "prop1val1").has("prop2", "prop2val2").limit(1).toList();
    assertEquals(1, res.size());
    res = graph.traversal().V().has("prop2", "prop2val2").has("prop1", "prop1val1").limit(1).toList();
    assertEquals(1, res.size());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Arrays(java.util.Arrays) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) Iterators(com.google.common.collect.Iterators) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) OrderList(org.janusgraph.graphdb.internal.OrderList) Cardinality(org.janusgraph.core.Cardinality) JanusGraphAssert.assertBackendHit(org.janusgraph.testutil.JanusGraphAssert.assertBackendHit) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) P(org.apache.tinkerpop.gremlin.process.traversal.P) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) P.not(org.apache.tinkerpop.gremlin.process.traversal.P.not) Edge(org.apache.tinkerpop.gremlin.structure.Edge) InMemoryStoreManager(org.janusgraph.diskstorage.inmemory.InMemoryStoreManager) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) PropertyKey(org.janusgraph.core.PropertyKey) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) JanusGraph(org.janusgraph.core.JanusGraph) Order(org.janusgraph.graphdb.internal.Order) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Text(org.janusgraph.core.attribute.Text) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JanusGraphAssert.assertNoBackendHit(org.janusgraph.testutil.JanusGraphAssert.assertNoBackendHit) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) Collections(java.util.Collections) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Contain(org.janusgraph.core.attribute.Contain) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 24 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project janusgraph by JanusGraph.

the class JanusGraphTest method testConcurrentConsistencyEnforcement.

/**
 * Execute multiple identical transactions concurrently. Note that since these transactions are running in the same process,
 * {@link org.janusgraph.diskstorage.locking.LocalLockMediator} is used to resolve lock contentions. If there is only
 * one lock needed in the whole transaction, exactly one transaction shall succeed and others shall fail due to local
 * lock contention. If there is more than one lock needed in the transaction, at most one transaction shall succeed
 * and others shall fail due to local lock contention.
 * @throws Exception
 */
@Test
public void testConcurrentConsistencyEnforcement() throws Exception {
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    JanusGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class).addKey(name).unique().buildCompositeIndex();
    mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK);
    EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make();
    mgmt.setConsistency(married, ConsistencyModifier.LOCK);
    mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
    finishSchema();
    JanusGraphVertex baseV = tx.addVertex("name", "base");
    newTx();
    final long baseVid = getId(baseV);
    final String nameA = "a", nameB = "b";
    final int parallelThreads = 4;
    // Only one lock is needed
    int[] results = executeParallelTransactions(tx -> {
        final JanusGraphVertex a = tx.addVertex();
        final JanusGraphVertex base = getV(tx, baseVid);
        base.addEdge("married", a);
    }, parallelThreads);
    int numOfSuccess = results[0];
    int numOfLockContentions = results[1];
    assertEquals(1, numOfSuccess);
    assertEquals(parallelThreads - 1, numOfLockContentions);
    // Two locks are needed. Note that the order of adding/modifying/deleting elements might not be consistent with
    // the order of real mutations during commit. Thus, it can be the case that one thread gets one lock and another
    // thread gets another, and both fail because they are unable to get the other lock.
    results = executeParallelTransactions(tx -> {
        tx.addVertex("name", nameA);
        final JanusGraphVertex b = tx.addVertex("name", nameB);
        b.addEdge("friend", b);
    }, parallelThreads);
    numOfSuccess = results[0];
    numOfLockContentions = results[1];
    assertTrue(numOfSuccess <= 1);
    assertEquals(parallelThreads - numOfSuccess, numOfLockContentions);
    newTx();
    final long numA = Iterables.size(tx.query().has("name", nameA).vertices());
    final long numB = Iterables.size(tx.query().has("name", nameB).vertices());
    assertTrue(numA <= 1);
    assertTrue(numB <= 1);
}
Also used : ManagementUtil(org.janusgraph.core.util.ManagementUtil) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) DisableDefaultSchemaMaker(org.janusgraph.core.schema.DisableDefaultSchemaMaker) JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Cardinality(org.janusgraph.core.Cardinality) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) Duration(java.time.Duration) Map(java.util.Map) JanusGraphAssert.assertNotContains(org.janusgraph.testutil.JanusGraphAssert.assertNotContains) Path(java.nio.file.Path) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) PropertyKey(org.janusgraph.core.PropertyKey) OUT(org.apache.tinkerpop.gremlin.structure.Direction.OUT) JanusGraphPredicateUtils(org.janusgraph.graphdb.query.JanusGraphPredicateUtils) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Arguments(org.junit.jupiter.params.provider.Arguments) VERBOSE_TX_RECOVERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) ADJUST_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ADJUST_LIMIT) RELATION(org.janusgraph.graphdb.internal.RelationCategory.RELATION) SCHEMA_CONSTRAINTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SCHEMA_CONSTRAINTS) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) FORCE_INDEX_USAGE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.FORCE_INDEX_USAGE) CUSTOM_ATTRIBUTE_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) TestGraphConfigs(org.janusgraph.testutil.TestGraphConfigs) Supplier(java.util.function.Supplier) Lists(com.google.common.collect.Lists) Change(org.janusgraph.core.log.Change) GhostVertexRemover(org.janusgraph.graphdb.olap.job.GhostVertexRemover) StreamSupport(java.util.stream.StreamSupport) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) LOG_SEND_DELAY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_SEND_DELAY) ALLOW_STALE_CONFIG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_STALE_CONFIG) T(org.apache.tinkerpop.gremlin.structure.T) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IDS_STORE_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDS_STORE_NAME) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Log(org.janusgraph.diskstorage.log.Log) Date(java.util.Date) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) NotImplementedException(org.apache.commons.lang.NotImplementedException) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) TextP(org.apache.tinkerpop.gremlin.process.traversal.TextP) MethodSource(org.junit.jupiter.params.provider.MethodSource) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) ElementLifeCycle(org.janusgraph.graphdb.internal.ElementLifeCycle) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Collection(java.util.Collection) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JanusGraphAssert.assertEmpty(org.janusgraph.testutil.JanusGraphAssert.assertEmpty) TestCategory(org.janusgraph.TestCategory) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) STORAGE_BATCH(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BATCH) Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) STORAGE_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND) JanusGraphFeature(org.janusgraph.testutil.JanusGraphFeature) JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) Message(org.janusgraph.diskstorage.log.Message) TRANSACTION_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TRANSACTION_LOG) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) GraphOfTheGodsFactory(org.janusgraph.example.GraphOfTheGodsFactory) Logger(org.slf4j.Logger) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) VertexList(org.janusgraph.core.VertexList) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Contain(org.janusgraph.core.attribute.Contain) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Arrays(java.util.Arrays) JanusGraphAssert.assertNotEmpty(org.janusgraph.testutil.JanusGraphAssert.assertNotEmpty) MessageReader(org.janusgraph.diskstorage.log.MessageReader) Geoshape(org.janusgraph.core.attribute.Geoshape) EDGE(org.janusgraph.graphdb.internal.RelationCategory.EDGE) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Tag(org.junit.jupiter.api.Tag) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) EnumMap(java.util.EnumMap) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) INITIAL_JANUSGRAPH_VERSION(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INITIAL_JANUSGRAPH_VERSION) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) PermanentLockingException(org.janusgraph.diskstorage.locking.PermanentLockingException) ArrayList(java.util.ArrayList) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) JanusGraphException(org.janusgraph.core.JanusGraphException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) MAX_COMMIT_TIME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MAX_COMMIT_TIME) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) ValueSource(org.junit.jupiter.params.provider.ValueSource) TX_CACHE_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TX_CACHE_SIZE) File(java.io.File) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SYSTEM_LOG_TRANSACTIONS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SYSTEM_LOG_TRANSACTIONS) ChronoUnit(java.time.temporal.ChronoUnit) HARD_MAX_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.HARD_MAX_LIMIT) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) SchemaAction(org.janusgraph.core.schema.SchemaAction) Order.asc(org.apache.tinkerpop.gremlin.process.traversal.Order.asc) OrderList(org.janusgraph.graphdb.internal.OrderList) BATCH_PROPERTY_PREFETCHING(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.BATCH_PROPERTY_PREFETCHING) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexSelectionUtil(org.janusgraph.graphdb.query.index.IndexSelectionUtil) P(org.apache.tinkerpop.gremlin.process.traversal.P) BOTH(org.apache.tinkerpop.gremlin.structure.Direction.BOTH) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) USER_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USER_LOG) Property(org.apache.tinkerpop.gremlin.structure.Property) SchemaViolationException(org.janusgraph.core.SchemaViolationException) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Sets(com.google.common.collect.Sets) LOG_READ_INTERVAL(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_READ_INTERVAL) List(java.util.List) TempDir(org.junit.jupiter.api.io.TempDir) JanusGraphDefaultSchemaMaker(org.janusgraph.core.schema.JanusGraphDefaultSchemaMaker) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) CUSTOM_SERIALIZER_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS) AUTO_TYPE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.AUTO_TYPE) HashMap(java.util.HashMap) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) JanusGraphAssert.assertContains(org.janusgraph.testutil.JanusGraphAssert.assertContains) Backend(org.janusgraph.diskstorage.Backend) Iterators(com.google.common.collect.Iterators) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) DB_CACHE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.DB_CACHE) LOG_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_BACKEND) IgnorePropertySchemaMaker(org.janusgraph.core.schema.IgnorePropertySchemaMaker) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BackendException(org.janusgraph.diskstorage.BackendException) MANAGEMENT_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MANAGEMENT_LOG) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Iterator(java.util.Iterator) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) STORAGE_READONLY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_READONLY) JanusGraph(org.janusgraph.core.JanusGraph) IN(org.apache.tinkerpop.gremlin.structure.Direction.IN) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Order(org.janusgraph.graphdb.internal.Order) PROPERTY(org.janusgraph.graphdb.internal.RelationCategory.PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) Collections(java.util.Collections) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 25 with org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project open-kilda by telstra.

the class FermaMirrorGroupRepository method exists.

@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MirrorGroupData(org.openkilda.model.MirrorGroup.MirrorGroupData) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) MirrorGroup(org.openkilda.model.MirrorGroup) MirrorGroupFrame(org.openkilda.persistence.ferma.frames.MirrorGroupFrame) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Aggregations

List (java.util.List)48 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)43 Optional (java.util.Optional)42 Edge (org.apache.tinkerpop.gremlin.structure.Edge)39 T (org.apache.tinkerpop.gremlin.structure.T)36 Lists (com.google.common.collect.Lists)35 Instant (java.time.Instant)34 ArrayList (java.util.ArrayList)34 IOException (java.io.IOException)33 Collectors.toList (java.util.stream.Collectors.toList)32 Direction (org.apache.tinkerpop.gremlin.structure.Direction)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 LabelP (org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP)31 URI (java.net.URI)30 UUID (java.util.UUID)30 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)30 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)29 Try (javaslang.control.Try)29 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)29