在 OrientDB 中查询 [英] Query in OrientDB

查看:44
本文介绍了在 OrientDB 中查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过 java 控制台打印查询,但没有任何结果.这是我的代码,有人可以帮助我.我是 OrientDB 的新手,我只是在学习.我需要的查询是知道两个节点之间的最短路径并在 Java 控制台上打印此查询.它没有给我任何错误,但没有任何结果.

I try to print a query through the java console but nothing comes out. this is my code someone could help me. I'm new to OrientDB and I'm just learning. The query I need is to know the shortest path between two nodes and print this query on the Java console. It does not give me any errors but nothing comes out.

public class Graph {
    private static final String DB_PATH = "C:/OrientDataBase/shortest_path";
    static OrientGraphNoTx DBGraph;
    static OrientGraphFactory factory;

 public static void main(String[] args) {
        factory = new OrientGraphFactory("plocal:"+DB_PATH);
        DBGraph = factory.getNoTx();
        HashMap<String, Vertex> nodes = new HashMap<String, Vertex>();

    for(int i = 0; i <= 1000; i++)
    {
        Vertex v = DBGraph.addVertex("class:V");
        v.setProperty("vertexID", i+"");
        nodes.put(i+"", v);
    }


    try(BufferedReader br = new BufferedReader(new FileReader("C:/OrientDataBase/sp1.csv"))) {
        int i=0;
        for(String line; (line = br.readLine()) !=null ; ) {
            if(i==0){
                i++;
            }
            else{
            String[] vertices = line.split(",");
            String vertex1 = vertices[0];
            String vertex2 = vertices[1];
            String weight= vertices[2];
            vertex2 = vertex2.replaceAll(" ", "");

            Vertex v1 = nodes.get(vertex1);
            Vertex v2 = nodes.get(vertex2);


            Edge eLives = DBGraph.addEdge(null, v1, v2, "belongs");
            eLives.setProperty("weight", weight);
            System.out.println(v1+","+v2+","+weight);

            String query = "select expand(shortestPath) from (select shortestPath(#10:0,#10:2,BOTH))";

            Iterable<OrientVertex> res = DBGraph.command(new OCommandSQL(query)).execute();

            while(res.iterator().hasNext()){
            OrientVertex v = res.iterator().next();
            System.out.println("rid: "+v.getId().toString()+"\tn:"+v.getProperty("n"));
            }

            }
        }

    }
    catch (IOException e) {
        e.printStackTrace();
    }



}
}

推荐答案

我试过你的代码,你在做查询时必须打勾,所以它变成:

I tried your code and you have to put the ticks when you do the query so, it becomes:

String query = "select expand(shortestPath) from (select shortestPath(#10:0,#10:2,'BOTH'))";

我使用了这个 csv 文件.

I used this csv file.

希望有帮助.

问候

这篇关于在 OrientDB 中查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆