orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.73k stars 869 forks source link

SQL Batch query #8373

Closed sedirmohammed closed 3 years ago

sedirmohammed commented 6 years ago

OrientDB Version: 2.2.35

Java Version: 1.8

Hello, my current situation is the following: I searching over the graph.command() command with sql a specific vertex and from this vertex i traverse over all outgoing edges, using the GremlinPipeline. Now I tried to use a SQL Batch query, but from here I don't know how I can get the returned objects to but them into the Gremlinpipeline. So this is my approach without the batch query:

    OrientDynaElementIterable orientDynaElementIterable = graph.command(new OCommandSQL("select from #18:0")).execute();
    GremlinPipeline pipe = new GremlinPipeline();
    pipe.start(orientDynaElementIterable);

The confusing here is that the orientDynaElementIterable object contains an ODocument object, but I first thought the GremlinPipeline needs Vertex objects. But for whatever reason it works and returns Vertex objects. Maybe it does an other query in the background to get a Vertex object?

An this is my approach with the batch query:

    String cmd = "begin\n";
    cmd += "let a = select from #18:0;";
    cmd += "let b = select from #18:1;";
    cmd += "let e = select from #18:2;";
    cmd += "COMMIT;";
    cmd += "return [ $a, $b ];";

    OrientDynaElementIterable orientDynaElementIterableBatch  = graph.command(new OCommandScript("sql", cmd)).execute();
    GremlinPipeline pipe = new GremlinPipeline();
    pipe.start(orientDynaElementIterableBatch);

Here I get the following exception: Exception in thread "main" java.lang.ClassCastException: com.orientechnologies.orient.core.db.record.ORecordLazyList cannot be cast to com.tinkerpop.blueprints.Vertex at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:85) at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:19) at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89) at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115) at com.tinkerpop.pipes.util.PipeHelper.fillCollection(PipeHelper.java:52) at com.tinkerpop.gremlin.java.GremlinPipeline.toList(GremlinPipeline.java:1564) at App.main(App.java:97)

So I don't understand the connection between the OrientDynaElementIterable object and the GremlinPipeline, or is it not provided to to start a GremlinPipeline after a batch?

Kind regards

luigidellaquila commented 6 years ago

Hi @adler4566

The problem here is that you are returning an array, that is not a vertex.

You can try the following, that probably will solve the issue:

...
cmd += "LET $result = SELECT unionAll($a, $b);";
cmd += "return $result;";

Thanks

Luigi

sedirmohammed commented 6 years ago

Hey @luigidellaquila ,

thank you for your approach, but it doesn't help. The GremlinPipeLine object returns nothing. If I turn on the debugger to illustrate the structure of the orientDynaElementIterableBatch object it shows me the following:

gscreenshot_2018-07-04-132037

Do you have an idea for this problem?

Kind regards Sedir Mohammed