Search in sources :

Example 1 with GraphFactory

use of org.vertexium.GraphFactory 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 GraphFactory

use of org.vertexium.GraphFactory in project vertexium by visallo.

the class GraphToolBase method run.

protected void run(String[] args) throws Exception {
    new JCommander(this, args);
    if (configFileName == null) {
        throw new RuntimeException("config is required");
    }
    Map config = new Properties();
    InputStream in = new FileInputStream(configFileName);
    try {
        ((Properties) config).load(in);
    } finally {
        in.close();
    }
    if (configPrefix != null) {
        config = MapUtils.getAllWithPrefix(config, configPrefix);
    }
    graph = new GraphFactory().createGraph(config);
}
Also used : GraphFactory(org.vertexium.GraphFactory) JCommander(com.beust.jcommander.JCommander) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 3 with GraphFactory

use of org.vertexium.GraphFactory in project vertexium by visallo.

the class VertexiumShell method run.

public int run(String[] args) throws Exception {
    Parameters params = new Parameters();
    JCommander j = new JCommander(params, args);
    if (params.help) {
        j.usage();
        return -1;
    }
    setTerminalType(params.terminalType, params.suppressColor);
    Map<String, String> config = ConfigurationUtils.loadConfig(params.getConfigFileNames(), params.configPropertyPrefix);
    Graph graph = new GraphFactory().createGraph(config);
    System.setProperty("groovysh.prompt", "vertexium");
    // IO must be constructed AFTER calling setTerminalType()/AnsiConsole.systemInstall(),
    // else wrapped System.out does not work on Windows.
    final IO io = new IO();
    Logger.io = io;
    CliVertexiumCypherQueryContext.setLabelPropertyName(params.cypherLabelProperty);
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    VertexiumScript.setGraph(graph);
    if (params.authorizations != null) {
        VertexiumScript.setAuthorizations(params.getAuthorizations(graph));
    }
    VertexiumScript.setTime(params.time);
    compilerConfiguration.setScriptBaseClass(VertexiumScript.class.getName());
    Binding binding = new Binding();
    GroovyShell groovyShell = new GroovyShell(this.getClass().getClassLoader(), binding, compilerConfiguration);
    Closure<Object> resultHook = new Closure<Object>(this) {

        @Override
        public Object call(Object... args) {
            Object obj = args[0];
            boolean showLastResult = !io.isQuiet() && (io.isVerbose() || Preferences.getShowLastResult());
            if (showLastResult) {
                // avoid String.valueOf here because it bypasses pretty-printing of Collections,
                // e.g. String.valueOf( ['a': 42] ) != ['a': 42].toString()
                io.out.println("@|bold ===>|@ " + VertexiumScript.resultToString(obj));
            }
            return null;
        }
    };
    groovysh = new Groovysh(io);
    setGroovyShell(groovysh, groovyShell);
    setResultHook(groovysh, resultHook);
    Groovysh shell = createShell();
    shell.execute("import " + Visibility.class.getPackage().getName() + ".*;");
    shell.execute("v = new " + LazyVertexMap.class.getName() + "();");
    shell.execute("e = new " + LazyEdgeMap.class.getName() + "();");
    shell.execute("g = " + VertexiumScript.class.getName() + ".getGraph();");
    shell.execute("auths = " + VertexiumScript.class.getName() + ".getAuthorizations();");
    shell.execute("time = " + VertexiumScript.class.getName() + ".getTime();");
    shell.execute("cypher = { code -> " + VertexiumScript.class.getName() + ".executeCypher(code) };");
    startGroovysh(params, shell, params.evalString, params.fileNames);
    return 0;
}
Also used : Binding(groovy.lang.Binding) GraphFactory(org.vertexium.GraphFactory) Closure(groovy.lang.Closure) IO(org.codehaus.groovy.tools.shell.IO) GroovyShell(groovy.lang.GroovyShell) Graph(org.vertexium.Graph) Groovysh(org.codehaus.groovy.tools.shell.Groovysh) JCommander(com.beust.jcommander.JCommander) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) LazyVertexMap(org.vertexium.cli.model.LazyVertexMap) LazyEdgeMap(org.vertexium.cli.model.LazyEdgeMap)

Aggregations

JCommander (com.beust.jcommander.JCommander)3 GraphFactory (org.vertexium.GraphFactory)3 Graph (org.vertexium.Graph)2 Binding (groovy.lang.Binding)1 Closure (groovy.lang.Closure)1 GroovyShell (groovy.lang.GroovyShell)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Properties (java.util.Properties)1 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)1 Groovysh (org.codehaus.groovy.tools.shell.Groovysh)1 IO (org.codehaus.groovy.tools.shell.IO)1 Authorizations (org.vertexium.Authorizations)1 LazyEdgeMap (org.vertexium.cli.model.LazyEdgeMap)1 LazyVertexMap (org.vertexium.cli.model.LazyVertexMap)1 VertexiumCypherQuery (org.vertexium.cypher.VertexiumCypherQuery)1 VertexiumCypherQueryContext (org.vertexium.cypher.VertexiumCypherQueryContext)1 VertexiumCypherResult (org.vertexium.cypher.VertexiumCypherResult)1 CypherCompilerContext (org.vertexium.cypher.ast.CypherCompilerContext)1