use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project grakn by graknlabs.
the class GraqlTraversal method getGraphTraversal.
/**
* Get the {@code GraphTraversal} that this {@code GraqlTraversal} represents.
*/
// Because 'union' accepts an array, we can't use generics
@SuppressWarnings("unchecked")
public GraphTraversal<Vertex, Map<String, Element>> getGraphTraversal(EmbeddedGraknTx<?> tx, Set<Var> vars) {
if (fragments().size() == 1) {
// If there are no disjunctions, we don't need to union them and get a performance boost
ImmutableList<Fragment> list = Iterables.getOnlyElement(fragments());
return getConjunctionTraversal(tx, tx.getTinkerTraversal().V(), vars, list);
} else {
Traversal[] traversals = fragments().stream().map(list -> getConjunctionTraversal(tx, __.V(), vars, list)).toArray(Traversal[]::new);
// This is a sneaky trick - we want to do a union but tinkerpop requires all traversals to start from
// somewhere, so we start from a single arbitrary vertex.
GraphTraversal traversal = tx.getTinkerTraversal().V().limit(1).union(traversals);
return selectVars(traversal, vars);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project grakn by graknlabs.
the class JanusPreviousPropertyStepTest method optimisedTraversal.
private GraphTraversal<Vertex, Vertex> optimisedTraversal(GraphTraversalSource g) {
GraphTraversal expected = g.V().outE().values("e prop").as("x");
GraphTraversal.Admin<Vertex, Object> admin = expected.asAdmin();
JanusPreviousPropertyStep<?> graphStep = new JanusPreviousPropertyStep<>(admin, "v prop", "x");
admin.addStep(graphStep);
admin.applyStrategies();
return expected;
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method testGeoshapAsGryo.
@Test
public void testGeoshapAsGryo() throws SerializationException {
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal();
GraphTraversal[] traversals = { g.addV().property("loc", Geoshape.box(0.1d, 0.2d, 0.3d, 0.4d)), g.addV().property("loc", Geoshape.box(0.1f, 0.3f, 0.5f, 0.6f)), g.addV().property("loc", Geoshape.circle(0.1d, 0.3d, 0.3d)), g.addV().property("loc", Geoshape.circle(0.2f, 0.4f, 0.5f)), g.addV().property("loc", Geoshape.point(1.0d, 4.0d)), g.addV().property("loc", Geoshape.point(1.0f, 1.0f)) };
serializationTest(traversals);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project cypher-for-gremlin by opencypher.
the class CypherOpProcessor method evalCypher.
private void evalCypher(Context context) throws OpProcessorException {
Map<String, Object> args = context.getRequestMessage().getArgs();
String cypher = (String) args.get(Tokens.ARGS_GREMLIN);
logger.info("Cypher: {}", cypher.replaceAll("\n", " "));
GraphTraversalSource gts = traversal(context);
DefaultGraphTraversal g = new DefaultGraphTraversal(gts.clone());
Map<String, Object> parameters = getParameters(args);
CypherAstWrapper ast = CypherAstWrapper.parse(cypher, parameters);
Translator<String, GroovyPredicate> stringTranslator = Translator.builder().gremlinGroovy().inlineParameters().build();
String gremlin = ast.buildTranslation(stringTranslator);
logger.info("Gremlin: {}", gremlin);
if (ast.getOptions().contains(EXPLAIN)) {
explainQuery(context, ast, gremlin);
return;
}
Translator<GraphTraversal, P> traversalTranslator = Translator.builder().traversal(g).build();
GraphTraversal<?, ?> traversal = ast.buildTranslation(traversalTranslator);
ReturnNormalizer returnNormalizer = ReturnNormalizer.create(ast.getReturnTypes());
Traversal<?, Map<String, Object>> normalizedTraversal = traversal.map(returnNormalizer::normalize);
inTransaction(gts, () -> handleIterator(context, normalizedTraversal));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project cypher-for-gremlin by opencypher.
the class TranslationOnlyClient method run.
@Override
public void run(String cypher) {
CypherAstWrapper ast = CypherAstWrapper.parse(cypher);
DefaultGraphTraversal g = new DefaultGraphTraversal();
Translator<GraphTraversal, P> translator = Translator.builder().traversal(g).build();
blackhole.consume(ast.buildTranslation(translator));
}
Aggregations