Search in sources :

Example 1 with Result

use of org.apache.tinkerpop.gremlin.driver.Result in project cypher-for-gremlin by opencypher.

the class CypherRemoteAcceptor method submit.

@Override
public Object submit(List<String> args) throws RemoteException {
    String line = String.join(" ", args);
    line = DriverRemoteAcceptor.getScript(line, shellEnvironment);
    try {
        final List<Result> resultSet = send(line);
        shellEnvironment.setVariable(RESULT, resultSet);
        return resultSet.stream().map(Result::getObject).iterator();
    } catch (Exception ex) {
        throw new RemoteException(ex);
    }
}
Also used : RemoteException(org.apache.tinkerpop.gremlin.jsr223.console.RemoteException) IOException(java.io.IOException) RemoteException(org.apache.tinkerpop.gremlin.jsr223.console.RemoteException) Result(org.apache.tinkerpop.gremlin.driver.Result)

Example 2 with Result

use of org.apache.tinkerpop.gremlin.driver.Result in project cypher-for-gremlin by opencypher.

the class CommonResultSets method explain.

static CypherResultSet explain(CypherAstWrapper ast) {
    Map<String, Object> explanation = new LinkedHashMap<>();
    Translator<String, GroovyPredicate> translator = Translator.builder().gremlinGroovy().inlineParameters().build();
    explanation.put("translation", ast.buildTranslation(translator));
    explanation.put("options", ast.getOptions().toString());
    Iterator<Result> iterator = singletonIterator(() -> new Result(explanation));
    return new CypherResultSet(iterator);
}
Also used : GroovyPredicate(org.opencypher.gremlin.translation.groovy.GroovyPredicate) LinkedHashMap(java.util.LinkedHashMap) Result(org.apache.tinkerpop.gremlin.driver.Result)

Example 3 with Result

use of org.apache.tinkerpop.gremlin.driver.Result in project cypher-for-gremlin by opencypher.

the class CypherResultSet method iterator.

/**
 * Returns a blocking iterator of the items streaming from the server to the client.
 *
 * @return query results iterator
 */
@Override
public Iterator<Map<String, Object>> iterator() {
    return new Iterator<Map<String, Object>>() {

        @Override
        public boolean hasNext() {
            return resultIterator.hasNext();
        }

        @Override
        public Map<String, Object> next() {
            Result result = resultIterator.next();
            Object row = result.getObject();
            return returnNormalizer.apply(row);
        }
    };
}
Also used : Iterator(java.util.Iterator) Result(org.apache.tinkerpop.gremlin.driver.Result)

Example 4 with Result

use of org.apache.tinkerpop.gremlin.driver.Result 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()));
}
Also used : P(org.apache.tinkerpop.gremlin.process.traversal.P) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReturnNormalizer(org.opencypher.gremlin.traversal.ReturnNormalizer) CypherAstWrapper(org.opencypher.gremlin.translation.CypherAstWrapper) Result(org.apache.tinkerpop.gremlin.driver.Result)

Example 5 with Result

use of org.apache.tinkerpop.gremlin.driver.Result in project janusgraph by JanusGraph.

the class RemoteGraphApp method createSchema.

@Override
public void createSchema() {
    LOGGER.info("creating schema");
    // get the schema request as a string
    final String req = createSchemaRequest();
    // submit the request to the server
    final ResultSet resultSet = client.submit(req);
    // drain the results completely
    Stream<Result> futureList = resultSet.stream();
    futureList.map(Result::toString).forEach(LOGGER::info);
}
Also used : ResultSet(org.apache.tinkerpop.gremlin.driver.ResultSet) Result(org.apache.tinkerpop.gremlin.driver.Result)

Aggregations

Result (org.apache.tinkerpop.gremlin.driver.Result)5 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 ResultSet (org.apache.tinkerpop.gremlin.driver.ResultSet)1 RemoteException (org.apache.tinkerpop.gremlin.jsr223.console.RemoteException)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 CypherAstWrapper (org.opencypher.gremlin.translation.CypherAstWrapper)1 GroovyPredicate (org.opencypher.gremlin.translation.groovy.GroovyPredicate)1 ReturnNormalizer (org.opencypher.gremlin.traversal.ReturnNormalizer)1