Search in sources :

Example 1 with CypherCompilerContext

use of org.vertexium.cypher.ast.CypherCompilerContext in project vertexium by visallo.

the class ExecuteCypherQuery method run.

private int run(String[] args) throws Exception {
    Parameters params = new Parameters();
    JCommander j = new JCommander(params, args);
    if (params.help) {
        j.usage();
        return -1;
    }
    Map<String, String> config = ConfigurationUtils.loadConfig(params.getConfigFileNames(), params.configPropertyPrefix);
    Graph graph = new GraphFactory().createGraph(config);
    Authorizations authorizations = params.getAuthorizations(graph);
    VertexiumCypherQueryContext ctx = new CliVertexiumCypherQueryContext(graph, authorizations);
    CliVertexiumCypherQueryContext.setLabelPropertyName(params.cypherLabelProperty);
    CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
    long startTime = System.currentTimeMillis();
    String queryString = params.query.stream().collect(Collectors.joining(" "));
    VertexiumCypherQuery query = VertexiumCypherQuery.parse(compilerContext, queryString);
    VertexiumCypherResult results = query.execute(ctx);
    results.stream().forEach(row -> {
        results.getColumnNames().forEach(column -> {
            System.out.println(row.getByName(column));
        });
    });
    long endTime = System.currentTimeMillis();
    LOGGER.info("total time: %.2fs", ((double) (endTime - startTime) / 1000.0));
    return 0;
}
Also used : VertexiumCypherResult(org.vertexium.cypher.VertexiumCypherResult) GraphFactory(org.vertexium.GraphFactory) Authorizations(org.vertexium.Authorizations) Graph(org.vertexium.Graph) CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) JCommander(com.beust.jcommander.JCommander) VertexiumCypherQueryContext(org.vertexium.cypher.VertexiumCypherQueryContext) VertexiumCypherQuery(org.vertexium.cypher.VertexiumCypherQuery)

Example 2 with CypherCompilerContext

use of org.vertexium.cypher.ast.CypherCompilerContext in project vertexium by visallo.

the class GraphGlue method givenHavingExecuted.

@Given("^having executed:$")
public void givenHavingExecuted(String queryString) {
    CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
    VertexiumCypherQuery.parse(compilerContext, queryString).execute(ctx);
}
Also used : CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) Given(cucumber.api.java.en.Given)

Example 3 with CypherCompilerContext

use of org.vertexium.cypher.ast.CypherCompilerContext in project vertexium by visallo.

the class VertexiumScript method executeCypher.

public static Object executeCypher(String code) {
    VertexiumCypherQueryContext ctx = new CliVertexiumCypherQueryContext(getGraph(), getAuthorizations());
    CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
    VertexiumCypherQuery query = VertexiumCypherQuery.parse(compilerContext, code);
    return query.execute(ctx);
}
Also used : CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) VertexiumCypherQueryContext(org.vertexium.cypher.VertexiumCypherQueryContext) VertexiumCypherQuery(org.vertexium.cypher.VertexiumCypherQuery)

Example 4 with CypherCompilerContext

use of org.vertexium.cypher.ast.CypherCompilerContext in project vertexium by visallo.

the class GraphGlue method whenExecutingQuery.

@When("^executing(.*)query:$")
public void whenExecutingQuery(String queryName, String queryString) {
    ctx.clearCounts();
    lastResults = null;
    lastCompileTimeException = null;
    lastRuntimeException = null;
    try {
        CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
        query = VertexiumCypherQuery.parse(compilerContext, queryString);
    } catch (Exception ex) {
        lastCompileTimeException = ex;
    }
    try {
        lastResults = query.execute(ctx);
        lastResults.size();
    } catch (Exception ex) {
        lastRuntimeException = ex;
    }
}
Also used : CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) VertexiumException(org.vertexium.VertexiumException) When(cucumber.api.java.en.When)

Example 5 with CypherCompilerContext

use of org.vertexium.cypher.ast.CypherCompilerContext in project vertexium by visallo.

the class GraphGlue method givenTheBinaryTreeGraph.

@Given("^the binary-tree-(\\d+) graph$")
public void givenTheBinaryTreeGraph(int number) throws Throwable {
    createGraph();
    String resourceName = "/org/vertexium/cypher/tck/binary-tree-" + number + ".cyp";
    InputStream treeIn = this.getClass().getResourceAsStream(resourceName);
    if (treeIn == null) {
        throw new VertexiumException("Could not find '" + resourceName + "'");
    }
    String cyp = IOUtils.toString(treeIn);
    CypherCompilerContext compilerContext = new CypherCompilerContext(ctx.getFunctions());
    VertexiumCypherQuery.parse(compilerContext, cyp).execute(ctx);
}
Also used : CypherCompilerContext(org.vertexium.cypher.ast.CypherCompilerContext) InputStream(java.io.InputStream) VertexiumException(org.vertexium.VertexiumException) Given(cucumber.api.java.en.Given)

Aggregations

CypherCompilerContext (org.vertexium.cypher.ast.CypherCompilerContext)5 Given (cucumber.api.java.en.Given)2 VertexiumException (org.vertexium.VertexiumException)2 VertexiumCypherQuery (org.vertexium.cypher.VertexiumCypherQuery)2 VertexiumCypherQueryContext (org.vertexium.cypher.VertexiumCypherQueryContext)2 JCommander (com.beust.jcommander.JCommander)1 When (cucumber.api.java.en.When)1 InputStream (java.io.InputStream)1 Authorizations (org.vertexium.Authorizations)1 Graph (org.vertexium.Graph)1 GraphFactory (org.vertexium.GraphFactory)1 VertexiumCypherResult (org.vertexium.cypher.VertexiumCypherResult)1