Skip to content

Commit

Permalink
Fix RETURN of multipe result sets as a collection in SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed Dec 17, 2019
1 parent 2f3d5d8 commit 92c687e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ public void serializeValue(final BytesContainer bytes, Object value, final OType
writeLinkCollection(bytes, ridCollection);
break;
case LINK:
if(value instanceof OResult && ((OResult) value).isElement()){
value = ((OResult) value).getElement().get();
}
if (!(value instanceof OIdentifiable))
throw new OValidationException("Value '" + value + "' is not a OIdentifiable");
writeOptimizedLink(bytes, (OIdentifiable) value);
Expand Down Expand Up @@ -573,6 +576,9 @@ private void writeEmbeddedCollection(final BytesContainer bytes, final Collectio
}

private OType getTypeFromValueEmbedded(final Object fieldValue) {
if(fieldValue instanceof OResult && ((OResult) fieldValue).isElement()){
return OType.LINK;
}
OType type = fieldValue instanceof OResult ? OType.EMBEDDED : OType.getTypeByValue(fieldValue);
if (type == OType.LINK && fieldValue instanceof ODocument && !((ODocument) fieldValue).getIdentity().isValid())
type = OType.EMBEDDED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
*/
public class RemoteQuerySupportTest {

private static final String SERVER_DIRECTORY = "./target/query";
private OServer server;
private OrientDB orientDB;
private ODatabaseDocument session;
private int oldPageSize;
private static final String SERVER_DIRECTORY = "./target/query";
private OServer server;
private OrientDB orientDB;
private ODatabaseDocument session;
private int oldPageSize;

@Before
public void before() throws Exception {
Expand Down Expand Up @@ -250,6 +250,29 @@ public void testBrokenParameter() {
}
}

@Test
public void testScriptWithRidbags() {
session.command("create class testScriptWithRidbagsV extends V");
session.command("create class testScriptWithRidbagsE extends E");
session.command("create vertex testScriptWithRidbagsV set name = 'a'");
session.command("create vertex testScriptWithRidbagsV set name = 'b'");

session.command("create edge testScriptWithRidbagsE from (select from testScriptWithRidbagsV where name = 'a') TO (select from testScriptWithRidbagsV where name = 'b');");


String script = "";
script += "BEGIN;";
script += "LET q1 = SELECT * FROM testScriptWithRidbagsV WHERE name = 'a';";
script += "LET q2 = SELECT * FROM testScriptWithRidbagsV WHERE name = 'b';";
script += "COMMIT ;";
script += "RETURN [$q1,$q2]";

OResultSet rs = session.execute("sql", script);

rs.forEachRemaining(x -> System.out.println(x));
rs.close();
}

@After
public void after() {
QUERY_REMOTE_RESULTSET_PAGE_SIZE.setValue(oldPageSize);
Expand Down

0 comments on commit 92c687e

Please sign in to comment.