Skip to content

Commit

Permalink
refactor: reduced usage of legacy query engine in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Oct 15, 2024
1 parent 0b353b9 commit 78764a1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -959,31 +959,24 @@ public void testAggregations() {

@Test
public void testLetOrder() {
OSQLSynchQuery sql =
new OSQLSynchQuery(
"SELECT"
+ " source,"
+ " $maxYear as maxYear"
+ " FROM"
+ " ("
+ " SELECT expand( $union ) "
+ " LET"
+ " $a = (SELECT 'A' as source, 2013 as year),"
+ " $b = (SELECT 'B' as source, 2012 as year),"
+ " $union = unionAll($a,$b) "
+ " ) "
+ " LET "
+ " $maxYear = max(year)"
+ " GROUP BY"
+ " source");
try {
List<ODocument> results = db.query(sql);
fail(
"Invalid query, usage of LET, aggregate functions and GROUP BY together is not"
+ " supported");
} catch (OCommandSQLParsingException x) {

}
String sql =
"SELECT"
+ " source,"
+ " $maxYear as maxYear"
+ " FROM"
+ " ("
+ " SELECT expand( $union ) "
+ " LET"
+ " $a = (SELECT 'A' as source, 2013 as year),"
+ " $b = (SELECT 'B' as source, 2012 as year),"
+ " $union = unionAll($a,$b) "
+ " ) "
+ " LET "
+ " $maxYear = max(year)"
+ " GROUP BY"
+ " source";
List results = db.query(sql).stream().toList();
assertEquals(results.size(), 2);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,26 +1713,25 @@ public void testCircularDependency() {
// - far depends on baz
// - baz depends on bar
// - bar depends on far
OSQLSynchQuery query =
new OSQLSynchQuery(
"MATCH {\n"
+ " class: testCircularDependency_Foo,\n"
+ " as: foo\n"
+ "}.out('testCircularDependency_Foo_Far') {\n"
+ " where: ($matched.baz IS NOT null),\n"
+ " as: far\n"
+ "}, {\n"
+ " as: foo\n"
+ "}.out('testCircularDependency_Foo_Bar') {\n"
+ " where: ($matched.far IS NOT null),\n"
+ " as: bar\n"
+ "}.out('testCircularDependency_Bar_Baz') {\n"
+ " where: ($matched.bar IS NOT null),\n"
+ " as: baz\n"
+ "} RETURN $matches");
String query =
"MATCH {\n"
+ " class: testCircularDependency_Foo,\n"
+ " as: foo\n"
+ "}.out('testCircularDependency_Foo_Far') {\n"
+ " where: ($matched.baz IS NOT null),\n"
+ " as: far\n"
+ "}, {\n"
+ " as: foo\n"
+ "}.out('testCircularDependency_Foo_Bar') {\n"
+ " where: ($matched.far IS NOT null),\n"
+ " as: bar\n"
+ "}.out('testCircularDependency_Bar_Baz') {\n"
+ " where: ($matched.bar IS NOT null),\n"
+ " as: baz\n"
+ "} RETURN $matches";

try {
db.query(query);
db.query(query).next();
fail();
} catch (OCommandExecutionException x) {
// passed the test
Expand All @@ -1756,18 +1755,16 @@ public void testUndefinedAliasDependency() {
.close();

// "bar" in the following query declares a dependency on the alias "baz", which doesn't exist.
OSQLSynchQuery query =
new OSQLSynchQuery(
"MATCH {\n"
+ " class: testUndefinedAliasDependency_Foo,\n"
+ " as: foo\n"
+ "}.out('testUndefinedAliasDependency_Foo_Bar') {\n"
+ " where: ($matched.baz IS NOT null),\n"
+ " as: bar\n"
+ "} RETURN $matches");

String query =
"MATCH {\n"
+ " class: testUndefinedAliasDependency_Foo,\n"
+ " as: foo\n"
+ "}.out('testUndefinedAliasDependency_Foo_Bar') {\n"
+ " where: ($matched.baz IS NOT null),\n"
+ " as: bar\n"
+ "} RETURN $matches";
try {
db.query(query);
db.query(query).next();
fail();
} catch (OCommandExecutionException x) {
// passed the test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import com.orientechnologies.BaseMemoryDatabase;
import com.orientechnologies.orient.core.exception.OQueryParsingException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import org.junit.Test;

public class OCustomSQLFunctionsTest extends BaseMemoryDatabase {
Expand Down Expand Up @@ -43,7 +41,8 @@ public void testAbsFloat() {
}

@Test(expected = OQueryParsingException.class)
public void testNonExistingFunction() {
db.query(new OSQLSynchQuery<ODocument>("select math_min('boom', 'boom') as boom"));
public void tresutestNonExistingFunction() {
OResultSet resut = db.query("select math_min('boom', 'boom') as boom");
resut.next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,10 @@ public void testFetchedJson() throws IOException {

final List<ODocument> result =
database
.getUnderlying()
.command(
new OSQLSynchQuery<ODocument>(
"select * from Profile where name = 'Barack' and surname = 'Obama'"))
.execute();
.command("select * from Profile where name = 'Barack' and surname = 'Obama'")
.stream()
.map(x -> (ODocument) x.toElement())
.toList();

for (final ODocument doc : result) {
final String jsonFull =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -128,8 +128,7 @@ public Void call() throws InterruptedException, IOException {

start = System.currentTimeMillis();
for (int j = 0; j < operations_read; j++) {
List<DummyObject> l =
tx.query(new OSQLSynchQuery<DummyObject>(" select * from DummyObject "));
List<OResult> l = tx.query(" select * from DummyObject ").stream().toList();
Assert.assertEquals(l.size(), operations_write);

// if ((j + 1) % 20000 == 0) {
Expand Down Expand Up @@ -246,8 +245,7 @@ public Void call() throws InterruptedException, IOException {

start = System.currentTimeMillis();
for (int j = 0; j < operations_read; j++) {
List<DummyObject> l =
tx.query(new OSQLSynchQuery<DummyObject>(" select * from DummyObject "));
List<OResult> l = tx.query(" select * from DummyObject ").stream().toList();
Assert.assertEquals(l.size(), operations_write);

// if ((j + 1) % 20000 == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.functions.OSQLFunctionAbstract;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -459,9 +458,7 @@ public void queryDate() {

@Test(expectedExceptions = OCommandSQLParsingException.class)
public void queryUndefinedFunction() {
database
.command(new OSQLSynchQuery<ODocument>("select blaaaa(salary) as max from Account"))
.execute();
database.command("select blaaaa(salary) as max from Account").next();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package com.orientechnologies.orient.test.database.auto;

import com.orientechnologies.orient.core.exception.OQueryParsingException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import static org.junit.Assert.assertTrue;

import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.Optional;
Expand Down Expand Up @@ -65,11 +65,11 @@ public void queryIndexes() {
@Test
public void queryMetadataNotSupported() {
try {
database
.command(new OSQLSynchQuery<ODocument>("select expand(indexes) from metadata:blaaa"))
.execute();
database.command("select expand(indexes) from metadata:blaaa").next();
Assert.fail();
} catch (OQueryParsingException e) {
} catch (UnsupportedOperationException e) {
} catch (OStorageException e) {
assertTrue(e.getCause() instanceof UnsupportedOperationException);
}
}
}

0 comments on commit 78764a1

Please sign in to comment.