use of org.opencypher.gremlin.translation.CypherAstWrapper 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.opencypher.gremlin.translation.CypherAstWrapper 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));
}
use of org.opencypher.gremlin.translation.CypherAstWrapper in project cypher-for-gremlin by opencypher.
the class GroovyCypherGremlinClient 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));
}
Translator<String, GroovyPredicate> translator = Translator.builder().gremlinGroovy().build(flavor);
String gremlin = ast.buildTranslation(translator);
Map<String, Object> extractedParameters = ast.getExtractedParameters();
CompletableFuture<ResultSet> resultSetFuture = client.submitAsync(gremlin, extractedParameters);
ReturnNormalizer returnNormalizer = ReturnNormalizer.create(ast.getReturnTypes());
return resultSetFuture.thenApply(ResultSet::iterator).thenApply(resultIterator -> new CypherResultSet(resultIterator, returnNormalizer::normalize));
}
use of org.opencypher.gremlin.translation.CypherAstWrapper in project cypher-for-gremlin by opencypher.
the class BytecodeCypherGremlinClient 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));
}
Translator<Bytecode, P> translator = Translator.builder().bytecode().build(flavor);
Bytecode bytecode = ast.buildTranslation(translator);
CompletableFuture<ResultSet> resultSetFuture = client.submitAsync(bytecode);
ReturnNormalizer returnNormalizer = ReturnNormalizer.create(ast.getReturnTypes());
return resultSetFuture.thenApply(ResultSet::iterator).thenApply(resultIterator -> new CypherResultSet(new TraverserIterator(resultIterator), returnNormalizer::normalize));
}
use of org.opencypher.gremlin.translation.CypherAstWrapper 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()));
}
Aggregations