Search in sources :

Example 1 with ResultSet

use of org.apache.tinkerpop.gremlin.driver.ResultSet 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));
}
Also used : GroovyPredicate(org.opencypher.gremlin.translation.groovy.GroovyPredicate) ResultSet(org.apache.tinkerpop.gremlin.driver.ResultSet) ReturnNormalizer(org.opencypher.gremlin.traversal.ReturnNormalizer) CypherAstWrapper(org.opencypher.gremlin.translation.CypherAstWrapper)

Example 2 with ResultSet

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

Example 3 with ResultSet

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

the class OpProcessorCypherGremlinClient method submitAsync.

@Override
public CompletableFuture<CypherResultSet> submitAsync(String cypher, Map<String, ?> parameters) {
    RequestMessage requestMessage = buildRequest(cypher, parameters).create();
    CompletableFuture<ResultSet> resultSetFuture = client.submitAsync(requestMessage);
    return resultSetFuture.thenApply(ResultSet::iterator).thenApply(CypherResultSet::new);
}
Also used : RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) ResultSet(org.apache.tinkerpop.gremlin.driver.ResultSet)

Example 4 with ResultSet

use of org.apache.tinkerpop.gremlin.driver.ResultSet in project DataX by alibaba.

the class AbstractGdbGraph method runInternal.

/**
 * @param dsl
 * @param parameters
 */
protected void runInternal(final String dsl, final Map<String, Object> parameters) throws Exception {
    final RequestOptions.Builder options = RequestOptions.build().timeout(DEFAULT_TIMEOUT);
    if (parameters != null && !parameters.isEmpty()) {
        parameters.forEach(options::addParameter);
    }
    final ResultSet results = this.client.submitAsync(dsl, options.create()).get(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
    results.all().get(DEFAULT_TIMEOUT + 1000, TimeUnit.MILLISECONDS);
}
Also used : RequestOptions(org.apache.tinkerpop.gremlin.driver.RequestOptions) ResultSet(org.apache.tinkerpop.gremlin.driver.ResultSet)

Example 5 with ResultSet

use of org.apache.tinkerpop.gremlin.driver.ResultSet 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

ResultSet (org.apache.tinkerpop.gremlin.driver.ResultSet)5 CypherAstWrapper (org.opencypher.gremlin.translation.CypherAstWrapper)2 ReturnNormalizer (org.opencypher.gremlin.traversal.ReturnNormalizer)2 RequestOptions (org.apache.tinkerpop.gremlin.driver.RequestOptions)1 Result (org.apache.tinkerpop.gremlin.driver.Result)1 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)1 Bytecode (org.apache.tinkerpop.gremlin.process.traversal.Bytecode)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 GroovyPredicate (org.opencypher.gremlin.translation.groovy.GroovyPredicate)1