org.apache.tinkerpop.gremlin.process.traversal.P Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.P. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithin_FloatArray() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatArrayValues());
    Float[] floatArray1 = new Float[]{1F, 2F, 3F};
    Float[] floatArray2 = new Float[]{4F, 5F, 6F};
    Float[] floatArray3 = new Float[]{7F, 8F, 9F};
    Float[] floatArray4 = new Float[]{10F, 11F, 12F};
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "A", "name", floatArray1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "A", "name", floatArray2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "A", "name", floatArray3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "A", "name", floatArray4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(floatArray1, floatArray3, floatArray4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #2
Source File: TestBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithin_LocalDateArray() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLocalDateArrayValues());
    LocalDate[] localDateArray1 = new LocalDate[]{LocalDate.now().minusDays(1), LocalDate.now().minusDays(2), LocalDate.now().minusDays(3)};
    LocalDate[] localDateArray2 = new LocalDate[]{LocalDate.now().minusDays(4), LocalDate.now().minusDays(5), LocalDate.now().minusDays(6)};
    LocalDate[] localDateArray3 = new LocalDate[]{LocalDate.now().minusDays(7), LocalDate.now().minusDays(8), LocalDate.now().minusDays(9)};
    LocalDate[] localDateArray4 = new LocalDate[]{LocalDate.now().minusDays(10), LocalDate.now().minusDays(11), LocalDate.now().minusDays(12)};
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "A", "name", localDateArray1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "A", "name", localDateArray2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "A", "name", localDateArray3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "A", "name", localDateArray4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(localDateArray1, localDateArray3, localDateArray4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #3
Source File: TestHasLabelAndId.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testGraphStepHasLabelWithinCollection() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c = this.sqlgGraph.addVertex(T.label, "C");
    Vertex d = this.sqlgGraph.addVertex(T.label, "D");
    this.sqlgGraph.tx().commit();
    GraphTraversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().hasLabel("A", "B");
    printTraversalForm(traversal);
    Assert.assertEquals(2, traversal.toList().size());
    traversal = this.sqlgGraph.traversal().V().hasLabel(P.within("A", "B"));
    Assert.assertEquals(2, traversal.toList().size());
    traversal = this.sqlgGraph.traversal().V().hasLabel(P.within(new HashSet<>(Arrays.asList("A", "B"))));
    Assert.assertEquals(2, traversal.toList().size());

    Assert.assertEquals(0, this.sqlgGraph.traversal().V(a, b).hasLabel(P.within("C")).toList().size());
    List<Vertex> vertices = this.sqlgGraph.traversal().V(a, b).hasLabel(P.within(new HashSet<>(Arrays.asList("A", "B", "D")))).toList();
    Assert.assertEquals(2, vertices.size());
}
 
Example #4
Source File: TestBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithin_IntegerArray() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsIntegerArrayValues());
    Integer[] intArray1 = new Integer[]{1, 2, 3};
    Integer[] intArray2 = new Integer[]{4, 5, 6};
    Integer[] intArray3 = new Integer[]{7, 8, 9};
    Integer[] intArray4 = new Integer[]{10, 11, 12};
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "A", "name", intArray1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "A", "name", intArray2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "A", "name", intArray3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "A", "name", intArray4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(intArray1, intArray3, intArray4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #5
Source File: TestGisBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithinPolygon() throws SQLException {
    LinearRing linearRing1 = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    Polygon polygon1 = new Polygon(new LinearRing[]{linearRing1});
    LinearRing linearRing2 = new LinearRing("1 1, 1 1, 1 2, 1 1, 1 1");
    Polygon polygon2 = new Polygon(new LinearRing[]{linearRing2});
    LinearRing linearRing3 = new LinearRing("2 2, 1 1, 1 2, 1 1, 2 2");
    Polygon polygon3 = new Polygon(new LinearRing[]{linearRing3});
    LinearRing linearRing4 = new LinearRing("1 3, 1 2, 2 2, 1 1, 1 3");
    Polygon polygon4 = new Polygon(new LinearRing[]{linearRing4});

    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("polygon", P.within(polygon1, polygon3, polygon4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #6
Source File: ClassificationService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the total effort points in all of the {@link ClassificationModel}s associated with the provided {@link FileModel}.
 */
public int getMigrationEffortPoints(FileModel fileModel)
{
    GraphTraversal<Vertex, Vertex> classificationPipeline = new GraphTraversalSource(getGraphContext().getGraph()).V(fileModel.getElement());
    classificationPipeline.in(ClassificationModel.FILE_MODEL);
    classificationPipeline.has(EffortReportModel.EFFORT, P.gt(0));
    classificationPipeline.has(WindupVertexFrame.TYPE_PROP, Text.textContains(ClassificationModel.TYPE));

    int classificationEffort = 0;
    for (Vertex v : classificationPipeline.toList())
    {
        Property<Integer> migrationEffort = v.property(ClassificationModel.EFFORT);
        if (migrationEffort.isPresent())
        {
            classificationEffort += migrationEffort.value();
        }
    }
    return classificationEffort;
}
 
Example #7
Source File: OLAPOperation.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
private void applyFilters(Set<LabelId> types, boolean includesRolePlayerEdge) {
        if (types == null || types.isEmpty()) return;
        Set<Integer> labelIds = types.stream().map(LabelId::getValue).collect(Collectors.toSet());

        Traversal<Vertex, Vertex> vertexFilter =
                __.has(Schema.VertexProperty.THING_TYPE_LABEL_ID.name(), P.within(labelIds));

        Traversal<Vertex, Edge> edgeFilter;
        if (filterAllEdges) {
            edgeFilter = __.bothE().limit(0);
        } else {
            edgeFilter = includesRolePlayerEdge ?
                    __.union(
                            __.bothE(Schema.EdgeLabel.ROLE_PLAYER.getLabel()),
                            __.bothE(Schema.EdgeLabel.ATTRIBUTE.getLabel()) ) :
//                                    .has(Schema.EdgeProperty.RELATION_TYPE_LABEL_ID.name(), P.within(labelIds))) :
                    __.bothE(Schema.EdgeLabel.ATTRIBUTE.getLabel()) ;
//                            .has(Schema.EdgeProperty.RELATION_TYPE_LABEL_ID.name(), P.within(labelIds));
        }

        graphComputer.vertices(vertexFilter).edges(edgeFilter);
    }
 
Example #8
Source File: MatchStepTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCalculateStartLabelCorrectly() {
    Traversal.Admin<?, ?> traversal = match(
            where(and(
                    as("a").out("created").as("b"),
                    as("b").in("created").count().is(eq(3)))),
            as("a").both().as("b"),
            where(as("b").in())).asAdmin();
    assertEquals("a", MatchStep.Helper.computeStartLabel(((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren()));
    /////
    traversal = match(
            where("a", P.neq("c")),
            as("a").out("created").as("b"),
            or(
                    as("a").out("knows").has("name", "vadas"),
                    as("a").in("knows").and().as("a").has(T.label, "person")
            ),
            as("b").in("created").as("c"),
            as("b").in("created").count().is(P.gt(1))).asAdmin();
    assertEquals("a", MatchStep.Helper.computeStartLabel(((MatchStep<?, ?>) traversal.getStartStep()).getGlobalChildren()));
}
 
Example #9
Source File: GryoSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final P p) {
    output.writeString(p instanceof ConnectiveP ?
            (p instanceof AndP ? "and" : "or") :
            p.getBiPredicate().toString());
    if (p instanceof ConnectiveP || p.getValue() instanceof Collection) {
        output.writeByte((byte) 0);
        final Collection<?> coll = p instanceof ConnectiveP ?
                ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue();
        output.writeInt(coll.size());
        coll.forEach(v -> kryo.writeClassAndObject(output, v));
    } else {
        output.writeByte((byte) 1);
        kryo.writeClassAndObject(output, p.getValue());
    }
}
 
Example #10
Source File: TinkerGraphStep.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
private Iterator<? extends Edge> edges() {
    final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
    final HasContainer indexedContainer = getIndexKey(Edge.class);
    final Optional<HasContainer> hasLabelContainer = findHasLabelStep();
    // ids are present, filter on them first
    if (null == this.ids)
        return Collections.emptyIterator();
    else if (this.ids.length > 0)
        return this.iteratorList(graph.edges(this.ids));
    else if (graph.ondiskOverflowEnabled && hasLabelContainer.isPresent())
        return graph.edgesByLabel((P<String>) hasLabelContainer.get().getPredicate());
    else
        return null == indexedContainer ?
                this.iteratorList(graph.edges()) :
                TinkerHelper.queryEdgeIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).stream()
                        .filter(edge -> HasContainer.testAll(edge, this.hasContainers))
                        .collect(Collectors.<Edge>toList()).iterator();
}
 
Example #11
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdateVertexIndicesInExistingGraph() {
    final TinkerGraph g = TinkerGraph.open();

    g.addVertex("name", "marko", "age", 29);
    g.addVertex("name", "stephen", "age", 35);

    // a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has()
    // to get into the Pipeline and evaluate what's going through it.  in this case, we know that at index
    // is not used because "stephen" and "marko" ages both pass through the pipeline.
    assertEquals(new Long(1), g.traversal().V().has("age", P.test((t, u) -> {
        assertTrue(t.equals(35) || t.equals(29));
        return true;
    }, 35)).has("name", "stephen").count().next());

    g.createIndex("name", Vertex.class);

    // another spy into the pipeline for index check.  in this case, we know that at index
    // is used because only "stephen" ages should pass through the pipeline due to the inclusion of the
    // key index lookup on "name".  If there's an age of something other than 35 in the pipeline being evaluated
    // then something is wrong.
    assertEquals(new Long(1), g.traversal().V().has("age", P.test((t, u) -> {
        assertEquals(35, t);
        return true;
    }, 35)).has("name", "stephen").count().next());
}
 
Example #12
Source File: TestHasLabelAndId.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testNeqWithinManyIDs() {
    Vertex a = sqlgGraph.addVertex("A");
    Vertex b1 = sqlgGraph.addVertex("B");
    Vertex b2 = sqlgGraph.addVertex("B");
    Vertex b3 = sqlgGraph.addVertex("B");
    Vertex b4 = sqlgGraph.addVertex("B");
    Vertex b5 = sqlgGraph.addVertex("B");
    Vertex b6 = sqlgGraph.addVertex("B");
    Vertex c = sqlgGraph.addVertex("C");

    a.addEdge("e_a", b1);
    a.addEdge("e_a", b2);
    a.addEdge("e_a", b3);
    a.addEdge("e_a", b4);
    a.addEdge("e_a", b5);
    a.addEdge("e_a", b6);
    a.addEdge("e_a", c);

    //uses tmp table to join on
    GraphTraversal<Vertex, Vertex> t = sqlgGraph.traversal().V(a).out().has(T.id, P.without(b1.id(), b2.id(), b3.id(), b4.id(), b5.id()));
    List<Vertex> vertices = t.toList();
    Assert.assertEquals(2, vertices.size());
    Assert.assertTrue(vertices.contains(b6));
    Assert.assertTrue(vertices.contains(c));
}
 
Example #13
Source File: TestBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithin_shortArray() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsShortArrayValues());
    short[] shortArray1 = new short[]{(short) 1, (short) 2, (short) 3};
    short[] shortArray2 = new short[]{(short) 4, (short) 5, (short) 6};
    short[] shortArray3 = new short[]{(short) 7, (short) 8, (short) 9};
    short[] shortArray4 = new short[]{(short) 10, (short) 11, (short) 12};
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "A", "name", shortArray1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "A", "name", shortArray2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "A", "name", shortArray3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "A", "name", shortArray4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(shortArray1, shortArray3, shortArray4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #14
Source File: ReceptionSearchDescription.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected GraphTraversal<Vertex, Vertex> initializeVertices(GraphWrapper graphWrapper) {
  // Get the stored search results
  List<Vertex> otherResults = otherSearch.getSearchResult();

  if (otherResults == null) {
    return EmptyGraph.instance().traversal().V();
  }
  // Filter by type as normal
  GraphTraversal<Vertex, Vertex> vertices = graphWrapper.getCurrentEntitiesFor(getType());

  // Return all the vertices which have a reception relation to the store results (other results):
  // The fact that all reception relations are inbound is a pure historical coincidence.
  return vertices.where(__.inE(getRelationNames()).otherV().is(P.within(otherResults)));
}
 
Example #15
Source File: TraversalConstructionBenchmark.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Benchmark
public GraphTraversal constructLong() throws Exception {
    return g.V().
            match(as("a").has("song", "name", "HERE COMES SUNSHINE"),
                  as("a").map(inE("followedBy").values("weight").mean()).as("b"),
                  as("a").inE("followedBy").as("c"),
                  as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")).
            select("d").by("name");
}
 
Example #16
Source File: GraphService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<T> findAllWithoutProperty(final String key, final Object value)
{
    return ExecutionStatistics.performBenchmarked("GraphService.findAllWithoutProperty(" + key + ")", () -> {
        //return (List<T>)findAllQuery().traverse(g -> g.hasNot(key).or(g.has(key, P.neq(value)))).toList(type);
        return findAllQuery().getRawTraversal().not(__.has(key, P.eq(value))).toList()
                .stream()
                .map(v -> frame((Vertex)v))
                .collect(Collectors.toList());
    });
}
 
Example #17
Source File: FullText.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * Build full text matching predicate (use in where(...))
 * Uses several columns for text search. This assumes PostgreSQL and concatenates column names with a space in between
 * just like we would by default build the index
 * @param configuration the full text configuration to use
 * @param plain should we use plain mode?
 * @param columns the columns to query
 * @param value the value to search for
 * @return the predicate
 */
public static P<String> fullTextMatch(String configuration, boolean plain, final List<String> columns, final String value){
	StringBuilder query=new StringBuilder(); 
	int count=1;
	for (String column : columns) {
		query.append("\""+column+"\"");
           if (count++ < columns.size()) {
           	query.append(" || ' ' || ");
           }
       }
	return new P<>(new FullText(configuration,query.toString(),plain),value);
}
 
Example #18
Source File: JavaTranslatorBenchmark.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Benchmark
public GraphTraversal.Admin<Vertex,Vertex> testTranslationLong() {
    return translator.translate(g.V().match(
            as("a").has("song", "name", "HERE COMES SUNSHINE"),
            as("a").map(inE("followedBy").values("weight").mean()).as("b"),
            as("a").inE("followedBy").as("c"),
            as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")).
            <String>select("d").by("name").asAdmin().getBytecode());
}
 
Example #19
Source File: WithinBenchmark.java    From sqlg with MIT License 5 votes vote down vote up
@SuppressWarnings("SameReturnValue")
@Benchmark
public long withinWithJoin() {
    this.sqlgGraph.configuration().setProperty("bulk.within.count", this.count - 1);
    List<Vertex> vertices = this.gt.V().hasLabel("Person").has("uid", P.within(this.smallUidSet)).toList();
    assertEquals(this.count, vertices.size());
    return 1000000;
}
 
Example #20
Source File: ValueComparison.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Map<Graql.Token.Comparator, Function<java.lang.String, P<java.lang.String>>> varPredicates() {
    Map<Graql.Token.Comparator, Function<java.lang.String, P<java.lang.String>>> predicates = new HashMap<>();

    predicates.putAll(comparablePredicates());
    predicates.put(Graql.Token.Comparator.CONTAINS, containsPredicate());

    return Collections.unmodifiableMap(predicates);
}
 
Example #21
Source File: FullTextSearchDescription.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> traversal, FullTextSearchParameter fullTextSearchParameter) {
  String term = fullTextSearchParameter.getTerm();
  // In the real world, the backup property was never reached due to the .coalesce step being
  // satisfied that the PersonNames' empty list mapped to a blank string.
  // A .union step for both however is quite satisfactory because when a user searches, the user wants
  // to search in all available data.
  traversal.where(__.union(prop1.getTraversal(), prop2.getTraversal())
                    .is(P.test(CONTAINS_STRING_PREDICATE, term)));
}
 
Example #22
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReadPWithJsonArray() throws Exception {
    // for some reason v3 is forgiving about the naked json array - leaving this here for backward compaitiblity,
    // but should be a g:List (i think)
    assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));

    final P o = P.within(Arrays.asList(1,2,3));
    assertEquals(o, mapper.readValue("{\"@type\": \"g:P\", \"@value\": {\"predicate\": \"within\", \"value\": [{\"@type\": \"g:Int32\", \"@value\": 1},{\"@type\": \"g:Int32\", \"@value\": 2},{\"@type\": \"g:Int32\", \"@value\": 3}]}}", Object.class));
}
 
Example #23
Source File: ConnectiveP.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    int result = 0, i = 0;
    for (final P p : this.predicates) {
        result ^= Integer.rotateLeft(p.hashCode(), i++);
    }
    return result;
}
 
Example #24
Source File: ComputerVerificationStrategyTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            // illegal
            {"__.where(__.out().values(\"name\"))", __.where(__.out().values("name")), false},
            {"__.local(out().out())", __.local(out().out()), false},
            // legal
            {"__.values(\"age\").union(max(), min(), sum())", __.values("age").union(max(), min(), sum()), true},
            {"__.count().sum()", __.count().sum(), true},
            {"__.where(\"a\",eq(\"b\")).out()", __.where("a", P.eq("b")).out(), true},
            {"__.where(and(outE(\"knows\"),outE(\"created\"))).values(\"name\")", __.where(__.and(outE("knows"), outE("created"))).values("name"), true},

    });
}
 
Example #25
Source File: FragmentImpl.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
static <T, U> GraphTraversal<T, U> assignVar(GraphTraversal<T, U> traversal, Variable var, Collection<Variable> vars) {
    if (!vars.contains(var)) {
        // This variable name has not been encountered before, remember it and use the 'as' step
        return traversal.as(var.symbol());
    } else {
        // This variable name has been encountered before, confirm it is the same
        return traversal.where(P.eq(var.symbol()));
    }
}
 
Example #26
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
private void testBulkWithinMultipleHasContrainers_assert(SqlgGraph sqlgGraph) {
    List<Vertex> persons = sqlgGraph.traversal().V()
            .hasLabel("God")
            .out()
            .has("name", "pete")
            .has("idNumber", P.within(1,2,3))
            .toList();
    Assert.assertEquals(2, persons.size());
}
 
Example #27
Source File: MatchTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_out_asXbX_matchXa_out_count_c__orXa_knows_b__b_in_count_c__and__c_isXgtX2XXXX() {
    return g.V().as("a").out().as("b").
            match(
                    as("a").out().count().as("c"),
                    or(
                            as("a").out("knows").as("b"),
                            as("b").in().count().as("c").and().as("c").is(P.gt(2))
                    )
            );
}
 
Example #28
Source File: ElementFactory.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
Stream<VertexElement> inFromSourceIdWithProperty(String startId, Schema.EdgeLabel edgeLabel,
                                                 Schema.EdgeProperty edgeProperty, Set<Integer> roleTypesIds) {
    return traversalSourceProvider.getTinkerTraversal()
            .V(startId)
            .inE(edgeLabel.getLabel())
            .has(edgeProperty.name(), org.apache.tinkerpop.gremlin.process.traversal.P.within(roleTypesIds))
            .outV()
            .toStream()
            .map(vertex -> buildVertexElement(vertex));
}
 
Example #29
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinFloat() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsFloatValues());
    this.sqlgGraph.addVertex(T.label, "A", "name", 1.1F);
    this.sqlgGraph.addVertex(T.label, "A", "name", 2.2F);
    this.sqlgGraph.addVertex(T.label, "A", "name", 3.3F);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(1.1F, 2.2F, 3.3F)).toList();
    Assert.assertEquals(3, vertices.size());
}
 
Example #30
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinInteger() {
    this.sqlgGraph.addVertex(T.label, "A", "name", 1);
    this.sqlgGraph.addVertex(T.label, "A", "name", 2);
    this.sqlgGraph.addVertex(T.label, "A", "name", 3);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A").has("name", P.within(1, 2, 3)).toList();
    Assert.assertEquals(3, vertices.size());
}