use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project cypher-for-gremlin by opencypher.
the class InMemoryCypherGremlinClient method submitAsync.
@Override
public CompletableFuture<CypherResultSet> submitAsync(String cypher, Map<String, ?> parameters) {
CypherAstWrapper ast;
try {
ast = CypherAstWrapper.parse(cypher, parameters);
} catch (Exception e) {
return completedFuture(exceptional(e));
}
if (ast.getOptions().contains(EXPLAIN)) {
return completedFuture(explain(ast));
}
DefaultGraphTraversal g = new DefaultGraphTraversal(gts.clone());
Translator<GraphTraversal, P> translator = Translator.builder().traversal(g).build();
GraphTraversal<?, ?> traversal = ast.buildTranslation(translator);
ReturnNormalizer returnNormalizer = ReturnNormalizer.create(ast.getReturnTypes());
List<Result> results = traversal.toStream().map(returnNormalizer::normalize).map(Result::new).collect(toList());
return completedFuture(new CypherResultSet(results.iterator()));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method serializationTest.
private void serializationTest(GraphTraversal[] traversals) throws SerializationException {
Builder mapper = GryoMapper.build().addRegistry(JanusGraphIoRegistry.instance());
MessageSerializer binarySerializer = new GryoMessageSerializerV1d0(mapper);
for (GraphTraversal traversal : traversals) {
Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
RequestMessage requestMessage = RequestMessage.build(Tokens.OPS_BYTECODE).processor("traversal").addArg(Tokens.ARGS_GREMLIN, expectedBytecode).create();
ByteBuf bb = binarySerializer.serializeRequestAsBinary(requestMessage, allocator);
final int mimeLen = bb.readByte();
bb.readBytes(new byte[mimeLen]);
RequestMessage deser = binarySerializer.deserializeRequest(bb);
Bytecode result = (Bytecode) deser.getArgs().get(Tokens.ARGS_GREMLIN);
assertEquals(expectedBytecode, result);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method testJanusGraphPredicatesAsGryo.
@Test
public void testJanusGraphPredicatesAsGryo() throws SerializationException {
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal();
// Janus Graph Geo, Text Predicates
GraphTraversal[] traversals = { g.E().has("place", Geo.geoIntersect(Geoshape.circle(37.97, 23.72, 50))), g.E().has("place", Geo.geoWithin(Geoshape.circle(37.97, 23.72, 50))), g.E().has("place", Geo.geoDisjoint(Geoshape.circle(37.97, 23.72, 50))), g.V().has("place", Geo.geoContains(Geoshape.point(37.97, 23.72))), g.V().has("name", Text.textContains("neptune")), g.V().has("name", Text.textContainsPrefix("nep")), g.V().has("name", Text.textContainsRegex("nep.*")), g.V().has("name", Text.textPrefix("n")), g.V().has("name", Text.textRegex(".*n.*")), g.V().has("name", Text.textContainsFuzzy("neptun")), g.V().has("name", Text.textFuzzy("nepitne")) };
serializationTest(traversals);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphSONModuleTest method testJanusGraphPredicatesAsGraphSON.
@ParameterizedTest(name = "GraphSON Version: {0}")
@EnumSource(value = GraphSONVersion.class, mode = EnumSource.Mode.EXCLUDE, names = { "V1_0" })
public void testJanusGraphPredicatesAsGraphSON(GraphSONVersion graphSONVersion) throws Exception {
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal();
GraphTraversal[] traversals = { g.E().has("place", Geo.geoIntersect(Geoshape.circle(37.97, 23.72, 50))), g.E().has("place", Geo.geoWithin(Geoshape.circle(37.97, 23.72, 50))), g.E().has("place", Geo.geoDisjoint(Geoshape.circle(37.97, 23.72, 50))), g.V().has("place", Geo.geoContains(Geoshape.point(37.97, 23.72))), g.V().has("name", Text.textContains("neptune")), g.V().has("name", Text.textContainsPrefix("nep")), g.V().has("name", Text.textContainsRegex("nep.*")), g.V().has("name", Text.textPrefix("n")), g.V().has("name", Text.textRegex(".*n.*")), g.V().has("name", Text.textContainsFuzzy("neptun")), g.V().has("name", Text.textFuzzy("nepitne")) };
graphsonSerializationTest(traversals, graphSONVersion);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method testTinkerPopPredicatesAsGryo.
/**
* This is necessary since we replace the default TinkerPop PSerializer
*
* @throws Exception
*/
@Test
public void testTinkerPopPredicatesAsGryo() throws SerializationException {
// Don't change this trivially. At the time of this writing (TinkerPop
// 3.2.3), this is how many P predicate methods were defined. If this
// fails, then JanusGraphPSerializer needs to be updated to add/remove
// any TinkerPop predicates!
assertEquals(15, Stream.of(P.class.getDeclaredMethods()).filter(m -> Modifier.isStatic(m.getModifiers())).filter(p -> {
log.debug("Predicate: {}", p);
return !p.isSynthetic();
}).count());
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal();
// TinkerPop Predicates
GraphTraversal[] traversals = { g.V().has("age", within(5000)), g.V().has("age", without(5000)), g.V().has("age", within(5000, 45)), g.V().has("age", inside(45, 5000)), g.V().and(has("age", between(45, 5000)), has("name", within("pluto"))), g.V().or(has("age", between(45, 5000)), has("name", within("pluto", "neptune"))) };
serializationTest(traversals);
}
Aggregations