Refine search
@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()); }
addGraphStructureEntry(g.V().out().out().path().next(), "Path", ""); addGraphStructureEntry(graph.edges().next().properties().next(), "Property", ""); addGraphStructureEntry(graph, "TinkerGraph", "`TinkerGraph` has a custom serializer that is registered as part of the `TinkerIoRegistry`."); addEntry("Graph Structure", g.V(1).out().out().tree().next(), "Tree", "", Compatibilities.GRYO_ONLY.match()); addGraphStructureEntry(graph.vertices().next(), "Vertex", ""); addGraphStructureEntry(graph.vertices().next().properties().next(), "VertexProperty", ""); addGraphProcessEntry(bulkSet, "BulkSet", "", before3_4_0); addGraphProcessEntry(g.V().hasLabel("person").out().in().tree().asAdmin().getBytecode(), "Bytecode", "The following `Bytecode` example represents the traversal of `g.V().hasLabel('person').out().in().tree()`. Obviously the serialized `Bytecode` woudl be quite different for the endless variations of commands that could be used together in the Gremlin language.", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(VertexProperty.Cardinality.list, "Cardinality", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(Column.keys, "Column", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray()); addGraphProcessEntry(g.V().hasLabel("person").asAdmin().nextTraverser(), "Traverser", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
public void shouldSupportStringSupplierLambdas() { GraphTraversalSource g = graph.traversal(); g = g.withStrategies(new TranslationStrategy(g, GroovyTranslator.of("g"))); final GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1) .V() .filter(Lambda.predicate("it.get().label().equals('person')")) .flatMap(Lambda.function("it.get().vertices(Direction.OUT)")) .map(Lambda.<Traverser<Object>, Integer>function("it.get().value('name').length()")) .sideEffect(Lambda.consumer("{ x -> x.sideEffects(\"lengthSum\", x.<Integer>sideEffects('lengthSum') + x.get()) }")) .order().by(Lambda.comparator("a,b -> a <=> b")) final List<Integer> sacks = new ArrayList<>(); final List<Integer> lengths = new ArrayList<>(); while (t.hasNext()) { final Traverser.Admin<Integer> traverser = t.nextTraverser(); sacks.add(traverser.sack()); lengths.add(traverser.get()); assertFalse(t.hasNext()); assertEquals(7, sacks.get(5).intValue()); assertEquals(24, t.getSideEffects().<Number>get("lengthSum").intValue()); final String script = GroovyTranslator.of("g").translate(t.getBytecode()); assertEquals("g.withSideEffect(\"lengthSum\",(int) 0).withSack((int) 1)" + ".V()" +
@Override public ReadEntity getEntity(UUID id, Integer rev, Collection collection, CustomEntityProperties customEntityProperties, CustomRelationProperties customRelationProperties) throws NotFoundException { GraphTraversal<Vertex, Vertex> fetchedEntity = entityFetcher.getEntity( traversal, id, rev, collection.getCollectionName() ); if (!fetchedEntity.hasNext()) { throw new NotFoundException(); } Vertex entityVertex = entityFetcher.getEntity(traversal, id, rev, collection.getCollectionName()).next(); GraphTraversal<Vertex, Vertex> entityT = traversal.V(entityVertex.id()); if (!entityT.asAdmin().clone().hasNext()) { throw new NotFoundException(); } String entityTypesStr = getProp(entityT.asAdmin().clone().next(), "types", String.class).orElse("[]"); if (!entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) { throw new NotFoundException(); } return new TinkerPopToEntityMapper(collection, traversal, mappings, customEntityProperties, customRelationProperties).mapEntity(entityT, true); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationShort() { return translator.translate(g.V().asAdmin().getBytecode()); }
private static void assertNumStep(int expectedResults, int expectedSteps, GraphTraversal traversal, Class<? extends Step>... expectedStepTypes) { int num = 0; while (traversal.hasNext()) { traversal.next(); num++; } // System.out.println(traversal); assertEquals(expectedResults, num); //Verify that steps line up with what is expected after Titan's optimizations are applied List<Step> steps = traversal.asAdmin().getSteps(); Set<Class<? extends Step>> expSteps = Sets.newHashSet(expectedStepTypes); int numSteps = 0; for (Step s : steps) { // System.out.println(s.getClass()); if (s.getClass().equals(GraphStep.class) || s.getClass().equals(StartStep.class)) continue; assertTrue(s.getClass().getName(), expSteps.contains(s.getClass())); numSteps++; } assertEquals(expectedSteps, numSteps); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldHandleMaps() { final String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap<Object,Object>() {{ put(3, "32"); put(Arrays.asList(1, 2, 3.1d), 4); }}).asAdmin().getBytecode()); assertEquals("g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int) 4)])", script); assertThatScriptOk(script, "g", g); }
GraphTraversal.Admin<S, E> admin = pipeline.asAdmin(); workingPipeline.asAdmin().getSteps().forEach(admin::addStep); } else { if (needsRememberingPosition(workingPipeline)) { finishPipeline(workingPipeline, state, origState); pipeline.where(workingPipeline); } else { GraphTraversal.Admin<S, E> admin = pipeline.asAdmin(); workingPipeline.asAdmin().getSteps().forEach(admin::addStep); } else { GraphTraversal.Admin<S, E> admin = pipeline.asAdmin(); workingPipeline.asAdmin().getSteps().forEach(admin::addStep);
public static GraphTraversal toTraversal(List<RelNode> relList) { final GraphTraversal traversal = __.identity(); TableDef tableDef = null; for(RelNode rel : relList) { if(rel instanceof GremlinTableScan) { GremlinTableScan tableScan = (GremlinTableScan) rel; tableDef = tableScan.getGremlinTable().getTableDef(); traversal.hasLabel(tableDef.label); } if(rel instanceof GremlinFilter) { GremlinFilter filter = (GremlinFilter) rel; RexNode condition = filter.getCondition(); FilterTranslator translator = new FilterTranslator(tableDef, filter.getRowType().getFieldNames()); GraphTraversal predicates = translator.translateMatch(condition); for(Step step : (List<Step>)predicates.asAdmin().getSteps()) { traversal.asAdmin().addStep(step); } } } return traversal; }
.getReadableProperties().entrySet().stream() .map(prop -> prop.getValue().traversalRaw().sideEffect(x -> x.get() .onSuccess(value -> { .toArray(GraphTraversal[]::new); entityT.asAdmin().clone().union(propertyGetters).forEachRemaining(x -> { entity.setProperties(properties); Vertex entityVertex = entityT.asAdmin().clone().next();
@Test public void shouldHandleEmptyMaps() { final Function identity = new Lambda.OneArgLambda("it.get()", "gremlin-groovy"); final String script = GroovyTranslator.of("g").translate(g.inject(Collections.emptyMap()).map(identity).asAdmin().getBytecode()); assertEquals("g.inject([]).map({it.get()})", script); assertThatScriptOk(script, "g", g); }
private void assertTranslation(final String expectedTranslation, final Object... objs) { final String script = GroovyTranslator.of("g").translate(g.inject(objs).asAdmin().getBytecode()); assertEquals(String.format("g.inject(%s)", expectedTranslation), script); assertThatScriptOk(script, "g", g); }
/** * Spawns a {@link GraphTraversal} by adding a vertex with the specified label. */ public GraphTraversal<Vertex, Vertex> addV(final String label) { final GraphTraversalSource clone = this.clone(); clone.bytecode.addStep(GraphTraversal.Symbols.addV, label); final GraphTraversal.Admin<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(clone); return traversal.addStep(new AddVertexStartStep(traversal, label)); }
public static TitanVertexStep<Vertex> getReverseTitanVertexStep(final MessageScope.Local<?> scope, final TitanTransaction graph) { FulgoraElementTraversal<Vertex,Edge> result = getReverseTraversal(scope,graph,null); result.asAdmin().applyStrategies(); verifyIncidentTraversal(result); return (TitanVertexStep)result.getStartStep(); }
public static JanusGraphVertexStep<Vertex> getReverseJanusGraphVertexStep(final MessageScope.Local<?> scope, final JanusGraphTransaction graph) { FulgoraElementTraversal<Vertex,Edge> result = getReverseTraversal(scope,graph,null); result.asAdmin().applyStrategies(); verifyIncidentTraversal(result); return (JanusGraphVertexStep)result.getStartStep(); }
public static TitanVertexStep<Vertex> getReverseTitanVertexStep(final MessageScope.Local<?> scope, final TitanTransaction graph) { FulgoraElementTraversal<Vertex,Edge> result = getReverseTraversal(scope,graph,null); result.asAdmin().applyStrategies(); verifyIncidentTraversal(result); return (TitanVertexStep)result.getStartStep(); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationWithStrategy() { return translator.translate(g.withStrategies(ReadOnlyStrategy.instance()) .withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()) .V().out().in("link").out().in("link").asAdmin().getBytecode()); } }